Browse Source

Add age_string attribute on User model

Apply user->age_string to user profile views
pull/27/head
Nafies Luthfi 7 years ago
parent
commit
9c5c3838a3
  1. 5
      app/User.php
  2. 2
      resources/views/users/partials/profile.blade.php
  3. 2
      resources/views/users/search.blade.php
  4. 13
      tests/Unit/UserTest.php

5
app/User.php

@ -279,4 +279,9 @@ class User extends Authenticatable
return $ageDetail; return $ageDetail;
} }
public function getAgeStringAttribute()
{
return '<div title="'.$this->age_detail.'">'.$this->age.' '.trans_choice('user.age_years', $this->age).'</div>';
}
} }

2
resources/views/users/partials/profile.blade.php

@ -33,7 +33,7 @@
@endif @endif
<tr> <tr>
<th>{{ trans('user.age') }}</th> <th>{{ trans('user.age') }}</th>
<td><div title="{{ $user->age_detail }}">{{ $user->age }} {{ trans_choice('user.age_years', $user->age) }}</div></td>
<td>{!! $user->age_string !!}</td>
</tr> </tr>
@if ($user->email) @if ($user->email)
<tr> <tr>

2
resources/views/users/search.blade.php

@ -30,7 +30,7 @@
<div class="panel-heading text-center"> <div class="panel-heading text-center">
{{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }} {{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }}
@if ($user->age) @if ($user->age)
<div title="{{ $user->age_detail }}">{{ $user->age }} {{ trans_choice('user.age_years', $user->age) }}</div>
{!! $user->age_string !!}
@endif @endif
</div> </div>
<div class="panel-body"> <div class="panel-body">

13
tests/Unit/UserTest.php

@ -212,4 +212,17 @@ class UserTest extends TestCase
['2018-02-02', null, '1997', null, '2017', '20 tahun'], ['2018-02-02', null, '1997', null, '2017', '20 tahun'],
]; ];
} }
/** @test */
public function user_has_age_string_attribute()
{
$today = '2018-02-02';
Carbon::setTestNow($today);
$user = factory(User::class)->make(['dob' => '1997-01-01']);
$ageString = '<div title="21 tahun, 1 bulan, 1 hari">21 tahun</div>';
$this->assertEquals($ageString, $user->age_string);
Carbon::setTestNow();
}
} }
Loading…
Cancel
Save