From 6d72fd6098dac9d3184b6732866cada4e61e0bff Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Fri, 7 Jun 2019 21:22:20 +0800 Subject: [PATCH 1/9] Add user year of birth attribute --- app/Http/Requests/Users/UpdateRequest.php | 7 +++++++ app/User.php | 2 +- database/migrations/2014_10_12_000000_create_users_table.php | 1 + resources/lang/en/user.php | 1 + resources/lang/id/user.php | 1 + resources/views/users/edit.blade.php | 7 ++++--- tests/Feature/UsersProfileTest.php | 2 ++ 7 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/Http/Requests/Users/UpdateRequest.php b/app/Http/Requests/Users/UpdateRequest.php index b77795c..289f09e 100644 --- a/app/Http/Requests/Users/UpdateRequest.php +++ b/app/Http/Requests/Users/UpdateRequest.php @@ -30,6 +30,7 @@ class UpdateRequest extends FormRequest 'name' => 'required|string|max:255', 'gender_id' => 'required|numeric', 'dob' => 'nullable|date|date_format:Y-m-d', + 'yob' => 'nullable|date_format:Y', 'dod' => 'nullable|date|date_format:Y-m-d', 'yod' => 'nullable|date_format:Y', 'phone' => 'nullable|string|max:255', @@ -59,6 +60,12 @@ class UpdateRequest extends FormRequest $formData['yod'] = $formData['yod']; } + if ($formData['dob']) { + $formData['yob'] = substr($formData['dob'], 0, 4); + } else { + $formData['yob'] = $formData['yob']; + } + if ($formData['password']) { $formData['password'] = bcrypt($formData['password']); } diff --git a/app/User.php b/app/User.php index 11257d7..f811a17 100644 --- a/app/User.php +++ b/app/User.php @@ -27,7 +27,7 @@ class User extends Authenticatable 'nickname', 'gender_id', 'name', 'email', 'password', 'address', 'phone', - 'dob', 'dod', 'yod', 'city', + 'dob', 'yob', 'dod', 'yod', 'city', 'father_id', 'mother_id', 'parent_id', ]; diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index bf4c98a..d446047 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -22,6 +22,7 @@ class CreateUsersTable extends Migration $table->uuid('mother_id')->nullable(); $table->uuid('parent_id')->nullable(); $table->date('dob')->nullable(); + $table->year('yob')->nullable(); $table->unsignedTinyInteger('birth_order')->nullable(); $table->date('dod')->nullable(); $table->year('yod')->nullable(); diff --git a/resources/lang/en/user.php b/resources/lang/en/user.php index 7b67031..40640c8 100644 --- a/resources/lang/en/user.php +++ b/resources/lang/en/user.php @@ -38,6 +38,7 @@ return [ 'mother' => 'Mother', 'parent' => 'Parent', 'dob' => 'Date of Birth', + 'yob' => 'Year of Birth', 'dod' => 'Date of Death', 'yod' => 'Year of Death', 'email' => 'Email', diff --git a/resources/lang/id/user.php b/resources/lang/id/user.php index e2425e0..6e5ac73 100644 --- a/resources/lang/id/user.php +++ b/resources/lang/id/user.php @@ -38,6 +38,7 @@ return [ 'mother' => 'Ibu', 'parent' => 'Orang Tua', 'dob' => 'Tanggal Lahir', + 'yob' => 'Tahun Lahir', 'dod' => 'Tanggal Meninggal', 'yod' => 'Tahun Meninggal', 'email' => 'Email', diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 158969d..1493cf0 100644 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -67,14 +67,15 @@ {!! FormField::text('nickname', ['label' => trans('user.nickname')]) !!}
{!! FormField::radios('gender_id', [1 => trans('app.male_code'), trans('app.female_code')], ['label' => trans('user.gender')]) !!}
-
{!! FormField::text('dob', ['label' => trans('user.dob'), 'placeholder' => trans('app.example').' 1959-07-20']) !!}
-
-
{!! FormField::text('birth_order', ['label' => trans('user.birth_order'), 'type' => 'number', 'min' => 1]) !!}
+
{!! FormField::text('yob', ['label' => trans('user.yob'), 'placeholder' => trans('app.example').' 1959']) !!}
+
{!! FormField::text('dob', ['label' => trans('user.dob'), 'placeholder' => trans('app.example').' 1959-07-20']) !!}
+
+
{!! FormField::text('yod', ['label' => trans('user.yod'), 'placeholder' => trans('app.example').' 2003']) !!}
{!! FormField::text('dod', ['label' => trans('user.dod'), 'placeholder' => trans('app.example').' 2003-10-17']) !!}
diff --git a/tests/Feature/UsersProfileTest.php b/tests/Feature/UsersProfileTest.php index 2bdbf9b..76f43dc 100644 --- a/tests/Feature/UsersProfileTest.php +++ b/tests/Feature/UsersProfileTest.php @@ -31,6 +31,7 @@ class UsersProfileTest extends TestCase 'name' => 'Nama User', 'gender_id' => 1, 'dob' => '1959-06-09', + 'yob' => '', 'dod' => '2003-10-17', 'yod' => '', 'address' => 'Jln. Angkasa, No. 70', @@ -46,6 +47,7 @@ class UsersProfileTest extends TestCase 'name' => 'Nama User', 'gender_id' => 1, 'dob' => '1959-06-09', + 'yob' => '1959', 'dod' => '2003-10-17', 'yod' => '2003', 'address' => 'Jln. Angkasa, No. 70', From cdde253fa92f925d7bfdeb9a94088c9325c3d446 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sat, 8 Jun 2019 07:07:43 +0800 Subject: [PATCH 2/9] Add age attribute for user model --- app/User.php | 14 ++++++++++++++ tests/Unit/UserTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/app/User.php b/app/User.php index f811a17..f852b21 100644 --- a/app/User.php +++ b/app/User.php @@ -2,6 +2,7 @@ namespace App; +use Carbon\Carbon; use Ramsey\Uuid\Uuid; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; @@ -230,4 +231,17 @@ class User extends Authenticatable { return $this->hasMany(Couple::class, 'manager_id'); } + + public function getAgeAttribute() + { + $age = null; + + if ($this->dob) { + $age = Carbon::parse($this->dob)->diffInYears($this->dod); + } elseif (!$this->dob && $this->yob) { + $age = date('Y') - $this->yob; + } + + return $age; + } } diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index 96c839d..17219bb 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -4,6 +4,7 @@ namespace Tests\Unit; use App\User; use App\Couple; +use Carbon\Carbon; use Tests\TestCase; use Illuminate\Support\Collection; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -145,4 +146,29 @@ class UserTest extends TestCase $this->assertInstanceOf(Collection::class, $user->managedCouples); $this->assertInstanceOf(Couple::class, $user->managedCouples->first()); } + + /** + * @test + * @dataProvider userAgeDataProvider + */ + public function user_has_age_attribute($now, $dob, $yob, $dod, $yod, $age) + { + Carbon::setTestNow($now); + $user = factory(User::class)->make([ + 'dob' => $dob, 'yob' => $yob, 'dod' => $dod, 'yod' => $yod, + ]); + + $this->assertEquals($age, $user->age); + + Carbon::setTestNow(); + } + + public function userAgeDataProvider() + { + // returning array of now, dob, yob, dod, yod, age. + return [ + ['2018-02-02 01:00:00', '1997-01-01', '1997', null, null, 21], + ['2018-02-02 01:00:00', null, '1997', null, null, 22], + ]; + } } From 79173ee26931525757c19268c1a3580ddb2d64f8 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sat, 8 Jun 2019 08:10:00 +0800 Subject: [PATCH 3/9] Use timespan for age attribute --- app/User.php | 18 ++++++++++++++---- tests/Unit/UserTest.php | 18 +++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/User.php b/app/User.php index f852b21..1205e80 100644 --- a/app/User.php +++ b/app/User.php @@ -236,10 +236,20 @@ class User extends Authenticatable { $age = null; - if ($this->dob) { - $age = Carbon::parse($this->dob)->diffInYears($this->dod); - } elseif (!$this->dob && $this->yob) { - $age = date('Y') - $this->yob; + if ($this->dob && !$this->dod) { + $age = Carbon::parse($this->dob)->timespan(); + } + if (!$this->dob && $this->yob) { + $age = (date('Y') - $this->yob).' tahun'; + } + if ($this->dob && $this->dod) { + $age = Carbon::parse($this->dob)->timespan($this->dod); + } + if (!$this->dob && $this->yob && !$this->dod && $this->yod) { + $age = ($this->yod - $this->yob).' tahun'; + } + if ($this->dob && $this->yob && $this->dod && $this->yod) { + $age = Carbon::parse($this->dob)->timespan($this->dod); } return $age; diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index 17219bb..bfa8286 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -151,9 +151,9 @@ class UserTest extends TestCase * @test * @dataProvider userAgeDataProvider */ - public function user_has_age_attribute($now, $dob, $yob, $dod, $yod, $age) + public function user_has_age_attribute($today, $dob, $yob, $dod, $yod, $age) { - Carbon::setTestNow($now); + Carbon::setTestNow($today); $user = factory(User::class)->make([ 'dob' => $dob, 'yob' => $yob, 'dod' => $dod, 'yod' => $yod, ]); @@ -163,12 +163,20 @@ class UserTest extends TestCase Carbon::setTestNow(); } + /** + * Provide data for calculating user age. + * Returning array of today, dob, yob, dod, yod, and age. + * + * @return array + */ public function userAgeDataProvider() { - // returning array of now, dob, yob, dod, yod, age. return [ - ['2018-02-02 01:00:00', '1997-01-01', '1997', null, null, 21], - ['2018-02-02 01:00:00', null, '1997', null, null, 22], + ['2018-02-02', '1997-01-01', '1997', null, null, '21 tahun, 1 bulan, 1 hari'], + ['2018-02-02', '1997-01-01', null, null, null, '21 tahun, 1 bulan, 1 hari'], + ['2018-02-02', null, '1997', null, null, '22 tahun'], + ['2018-02-02', '1997-01-01', '1997', '2017-01-01', '2017', '20 tahun'], + ['2018-02-02', null, '1997', null, '2017', '20 tahun'], ]; } } From fbb1945b3ff19723ec0c1963e0a9c96ca2ac0e1e Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sat, 8 Jun 2019 09:22:36 +0800 Subject: [PATCH 4/9] Use timespan for year-only data --- app/User.php | 5 +++-- tests/Unit/UserTest.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/User.php b/app/User.php index 1205e80..5cf5b62 100644 --- a/app/User.php +++ b/app/User.php @@ -235,18 +235,19 @@ class User extends Authenticatable public function getAgeAttribute() { $age = null; + $yearOnlySuffix = Carbon::now()->format('-m-d'); if ($this->dob && !$this->dod) { $age = Carbon::parse($this->dob)->timespan(); } if (!$this->dob && $this->yob) { - $age = (date('Y') - $this->yob).' tahun'; + $age = Carbon::parse($this->yob.$yearOnlySuffix)->timespan(); } if ($this->dob && $this->dod) { $age = Carbon::parse($this->dob)->timespan($this->dod); } if (!$this->dob && $this->yob && !$this->dod && $this->yod) { - $age = ($this->yod - $this->yob).' tahun'; + $age = Carbon::parse($this->yob.$yearOnlySuffix)->timespan($this->yod.$yearOnlySuffix); } if ($this->dob && $this->yob && $this->dod && $this->yod) { $age = Carbon::parse($this->dob)->timespan($this->dod); diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index bfa8286..212bb7b 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -174,7 +174,7 @@ class UserTest extends TestCase return [ ['2018-02-02', '1997-01-01', '1997', null, null, '21 tahun, 1 bulan, 1 hari'], ['2018-02-02', '1997-01-01', null, null, null, '21 tahun, 1 bulan, 1 hari'], - ['2018-02-02', null, '1997', null, null, '22 tahun'], + ['2018-02-02', null, '1997', null, null, '21 tahun'], ['2018-02-02', '1997-01-01', '1997', '2017-01-01', '2017', '20 tahun'], ['2018-02-02', null, '1997', null, '2017', '20 tahun'], ]; From e2daa6abb830eb99264fc15e1ec6c096bc0300e7 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sat, 8 Jun 2019 09:31:58 +0800 Subject: [PATCH 5/9] Change age attribute to age_detail --- app/User.php | 16 ++++++++-------- tests/Unit/UserTest.php | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/User.php b/app/User.php index 5cf5b62..fb18e7a 100644 --- a/app/User.php +++ b/app/User.php @@ -232,27 +232,27 @@ class User extends Authenticatable return $this->hasMany(Couple::class, 'manager_id'); } - public function getAgeAttribute() + public function getAgeDetailAttribute() { - $age = null; + $ageDetail = null; $yearOnlySuffix = Carbon::now()->format('-m-d'); if ($this->dob && !$this->dod) { - $age = Carbon::parse($this->dob)->timespan(); + $ageDetail = Carbon::parse($this->dob)->timespan(); } if (!$this->dob && $this->yob) { - $age = Carbon::parse($this->yob.$yearOnlySuffix)->timespan(); + $ageDetail = Carbon::parse($this->yob.$yearOnlySuffix)->timespan(); } if ($this->dob && $this->dod) { - $age = Carbon::parse($this->dob)->timespan($this->dod); + $ageDetail = Carbon::parse($this->dob)->timespan($this->dod); } if (!$this->dob && $this->yob && !$this->dod && $this->yod) { - $age = Carbon::parse($this->yob.$yearOnlySuffix)->timespan($this->yod.$yearOnlySuffix); + $ageDetail = Carbon::parse($this->yob.$yearOnlySuffix)->timespan($this->yod.$yearOnlySuffix); } if ($this->dob && $this->yob && $this->dod && $this->yod) { - $age = Carbon::parse($this->dob)->timespan($this->dod); + $ageDetail = Carbon::parse($this->dob)->timespan($this->dod); } - return $age; + return $ageDetail; } } diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index 212bb7b..34b3e07 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -149,27 +149,27 @@ class UserTest extends TestCase /** * @test - * @dataProvider userAgeDataProvider + * @dataProvider userAgeDetailDataProvider */ - public function user_has_age_attribute($today, $dob, $yob, $dod, $yod, $age) + public function user_has_age_detail_attribute($today, $dob, $yob, $dod, $yod, $age) { Carbon::setTestNow($today); $user = factory(User::class)->make([ 'dob' => $dob, 'yob' => $yob, 'dod' => $dod, 'yod' => $yod, ]); - $this->assertEquals($age, $user->age); + $this->assertEquals($age, $user->age_detail); Carbon::setTestNow(); } /** - * Provide data for calculating user age. + * Provide data for calculating user age detail. * Returning array of today, dob, yob, dod, yod, and age. * * @return array */ - public function userAgeDataProvider() + public function userAgeDetailDataProvider() { return [ ['2018-02-02', '1997-01-01', '1997', null, null, '21 tahun, 1 bulan, 1 hari'], From 20cf6e079438c031ba6c143ec4b5245c9bd3165a Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sat, 8 Jun 2019 09:34:41 +0800 Subject: [PATCH 6/9] Add numeric age attribute for user model --- app/User.php | 24 ++++++++++++++++++++++++ tests/Unit/UserTest.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/app/User.php b/app/User.php index fb18e7a..aa24dcf 100644 --- a/app/User.php +++ b/app/User.php @@ -232,6 +232,30 @@ class User extends Authenticatable return $this->hasMany(Couple::class, 'manager_id'); } + public function getAgeAttribute() + { + $ageDetail = null; + $yearOnlySuffix = Carbon::now()->format('-m-d'); + + if ($this->dob && !$this->dod) { + $ageDetail = Carbon::parse($this->dob)->diffInYears(); + } + if (!$this->dob && $this->yob) { + $ageDetail = Carbon::parse($this->yob.$yearOnlySuffix)->diffInYears(); + } + if ($this->dob && $this->dod) { + $ageDetail = Carbon::parse($this->dob)->diffInYears($this->dod); + } + if (!$this->dob && $this->yob && !$this->dod && $this->yod) { + $ageDetail = Carbon::parse($this->yob.$yearOnlySuffix)->diffInYears($this->yod.$yearOnlySuffix); + } + if ($this->dob && $this->yob && $this->dod && $this->yod) { + $ageDetail = Carbon::parse($this->dob)->diffInYears($this->dod); + } + + return $ageDetail; + } + public function getAgeDetailAttribute() { $ageDetail = null; diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index 34b3e07..b2ce620 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -149,6 +149,39 @@ class UserTest extends TestCase /** * @test + * @dataProvider userAgeDataProvider + */ + public function user_has_age_attribute($today, $dob, $yob, $dod, $yod, $age) + { + Carbon::setTestNow($today); + $user = factory(User::class)->make([ + 'dob' => $dob, 'yob' => $yob, 'dod' => $dod, 'yod' => $yod, + ]); + + $this->assertEquals($age, $user->age); + + Carbon::setTestNow(); + } + + /** + * Provide data for calculating user age. + * Returning array of today, dob, yob, dod, yod, and age. + * + * @return array + */ + public function userAgeDataProvider() + { + return [ + ['2018-02-02', '1997-01-01', '1997', null, null, 21], + ['2018-02-02', '1997-01-01', null, null, null, 21], + ['2018-02-02', null, '1997', null, null, 21], + ['2018-02-02', '1997-01-01', '1997', '2017-01-01', '2017', 20], + ['2018-02-02', null, '1997', null, '2017', 20], + ]; + } + + /** + * @test * @dataProvider userAgeDetailDataProvider */ public function user_has_age_detail_attribute($today, $dob, $yob, $dod, $yod, $age) From 984de08de3022a8629b1368b82317fce4435aa69 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sat, 8 Jun 2019 09:46:55 +0800 Subject: [PATCH 7/9] Show user age on profile page --- resources/lang/en/user.php | 2 ++ resources/lang/id/user.php | 2 ++ resources/views/users/partials/profile.blade.php | 4 ++++ resources/views/users/search.blade.php | 5 ++++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/resources/lang/en/user.php b/resources/lang/en/user.php index 40640c8..ae87d63 100644 --- a/resources/lang/en/user.php +++ b/resources/lang/en/user.php @@ -18,6 +18,8 @@ return [ 'nieces' => 'Nieces', 'marriages' => 'Marriages', 'birth_order' => 'Birth Order', + 'age' => 'Age', + 'age_years' => 'year|years', // Actions 'edit' => 'Edit Profile', diff --git a/resources/lang/id/user.php b/resources/lang/id/user.php index 6e5ac73..ced0d3b 100644 --- a/resources/lang/id/user.php +++ b/resources/lang/id/user.php @@ -18,6 +18,8 @@ return [ 'nieces' => 'Keponakan', 'marriages' => 'Pernikahan', 'birth_order' => 'Anak ke', + 'age' => 'Usia', + 'age_years' => 'tahun', // Actions 'edit' => 'Edit Profil', diff --git a/resources/views/users/partials/profile.blade.php b/resources/views/users/partials/profile.blade.php index bc58061..3438ab9 100644 --- a/resources/views/users/partials/profile.blade.php +++ b/resources/views/users/partials/profile.blade.php @@ -31,6 +31,10 @@ {{ $user->dod }} @endif + + {{ trans('user.age') }} +
{{ $user->age }} {{ trans_choice('user.age_years', $user->age) }}
+ @if ($user->email) {{ trans('user.email') }} diff --git a/resources/views/users/search.blade.php b/resources/views/users/search.blade.php index eb139e7..be01f27 100644 --- a/resources/views/users/search.blade.php +++ b/resources/views/users/search.blade.php @@ -27,8 +27,11 @@ @foreach ($chunkedUser as $user)
-
+
{{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }} + @if ($user->age) +
{{ $user->age }} {{ trans_choice('user.age_years', $user->age) }}
+ @endif

{{ $user->profileLink() }} ({{ $user->gender }})

From 9c5c3838a3b21c4b911e69b1ad60bac7bf4718b1 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sat, 8 Jun 2019 09:51:13 +0800 Subject: [PATCH 8/9] Add age_string attribute on User model Apply user->age_string to user profile views --- app/User.php | 5 +++++ resources/views/users/partials/profile.blade.php | 2 +- resources/views/users/search.blade.php | 2 +- tests/Unit/UserTest.php | 13 +++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/User.php b/app/User.php index aa24dcf..cd98314 100644 --- a/app/User.php +++ b/app/User.php @@ -279,4 +279,9 @@ class User extends Authenticatable return $ageDetail; } + + public function getAgeStringAttribute() + { + return '
'.$this->age.' '.trans_choice('user.age_years', $this->age).'
'; + } } diff --git a/resources/views/users/partials/profile.blade.php b/resources/views/users/partials/profile.blade.php index 3438ab9..56e4d8a 100644 --- a/resources/views/users/partials/profile.blade.php +++ b/resources/views/users/partials/profile.blade.php @@ -33,7 +33,7 @@ @endif {{ trans('user.age') }} -
{{ $user->age }} {{ trans_choice('user.age_years', $user->age) }}
+ {!! $user->age_string !!} @if ($user->email) diff --git a/resources/views/users/search.blade.php b/resources/views/users/search.blade.php index be01f27..ffad122 100644 --- a/resources/views/users/search.blade.php +++ b/resources/views/users/search.blade.php @@ -30,7 +30,7 @@
{{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }} @if ($user->age) -
{{ $user->age }} {{ trans_choice('user.age_years', $user->age) }}
+ {!! $user->age_string !!} @endif
diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index b2ce620..ba231d5 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -212,4 +212,17 @@ class UserTest extends TestCase ['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 = '
21 tahun
'; + $this->assertEquals($ageString, $user->age_string); + + Carbon::setTestNow(); + } } From 4befaaa5b945ff1af0790bb8a236bae715ccbc92 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 9 Jun 2019 20:39:00 +0800 Subject: [PATCH 9/9] Show age on user profile only if age is exists --- resources/views/users/partials/profile.blade.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/views/users/partials/profile.blade.php b/resources/views/users/partials/profile.blade.php index 56e4d8a..3610084 100644 --- a/resources/views/users/partials/profile.blade.php +++ b/resources/views/users/partials/profile.blade.php @@ -33,7 +33,11 @@ @endif {{ trans('user.age') }} - {!! $user->age_string !!} + + @if ($user->age) + {!! $user->age_string !!} + @endif + @if ($user->email)