diff --git a/.env.example b/.env.example index 668c06f..55b5223 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ -APP_NAME=Laravel APP_ENV=local APP_KEY= APP_DEBUG=true diff --git a/app/Couple.php b/app/Couple.php index f2db974..c512e02 100644 --- a/app/Couple.php +++ b/app/Couple.php @@ -15,4 +15,17 @@ class Couple extends Model { return $this->belongsTo(User::class); } + + public function childs() + { + return $this->hasMany(User::class, 'parent_id'); + } + + public function addChild(User $user) + { + $user->parent_id = $this->id; + $user->father_id = $this->husband_id; + $user->mother_id = $this->wife_id; + $user->save(); + } } diff --git a/app/Http/Controllers/UserMarriagesController.php b/app/Http/Controllers/UserMarriagesController.php new file mode 100644 index 0000000..adf6e0a --- /dev/null +++ b/app/Http/Controllers/UserMarriagesController.php @@ -0,0 +1,15 @@ +marriages()->with('husband', 'wife')->withCount('childs')->get(); + return view('users.marriages', compact('user', 'marriages')); + } +} diff --git a/app/User.php b/app/User.php index 57262a9..40c9a9f 100644 --- a/app/User.php +++ b/app/User.php @@ -149,6 +149,14 @@ class User extends Authenticatable return $this->belongsToMany(User::class, 'couples', 'wife_id', 'husband_id')->withPivot(['id'])->withTimestamps(); } + public function marriages() + { + if ($this->gender_id == 1) + return $this->hasMany(Couple::class, 'husband_id'); + + return $this->hasMany(Couple::class, 'wife_id'); + } + public function siblings() { if (is_null($this->father_id) && is_null($this->mother_id) && is_null($this->parent_id)) diff --git a/config/app.php b/config/app.php index 85dbeb4..0baa4fa 100644 --- a/config/app.php +++ b/config/app.php @@ -12,7 +12,7 @@ return [ | any other location as required by the application or its packages. */ - 'name' => env('APP_NAME', 'Laravel'), + 'name' => 'Silsilah', /* |-------------------------------------------------------------------------- diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 697591e..dc96fc0 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -1,5 +1,6 @@ state(User::class, 'male', function (Faker\Generator $faker) { $factory->state(User::class, 'female', function (Faker\Generator $faker) { return ['gender_id' => 2]; +}); + +$factory->define(Couple::class, function (Faker\Generator $faker) { + $name = $faker->name; + return [ + 'husband_id' => function () { + return factory(User::class)->states('male')->create()->id; + }, + 'wife_id' => function () { + return factory(User::class)->states('female')->create()->id; + }, + ]; }); \ No newline at end of file diff --git a/resources/lang/en/couple.php b/resources/lang/en/couple.php new file mode 100644 index 0000000..ddbcdc4 --- /dev/null +++ b/resources/lang/en/couple.php @@ -0,0 +1,14 @@ + 'Show Marriage Profile', + 'childs_count' => 'Childs Count', + 'grand_childs_count' => 'Grand Childs Count', + + // Attributes + 'husband' => 'Head of Family', + 'wive' => 'Wife', + 'marriage_date' => 'Marriage Date', + 'divorce_date' => 'Divorce Date', +]; \ No newline at end of file diff --git a/resources/lang/en/user.php b/resources/lang/en/user.php index 4e277ff..672ec1a 100644 --- a/resources/lang/en/user.php +++ b/resources/lang/en/user.php @@ -16,6 +16,7 @@ return [ 'grand_mother' => 'Grand Mother', 'grand_father' => 'Grand Father', 'nieces' => 'Nieces', + 'marriages' => 'Marriages', // Actions 'edit' => 'Edit Profile', diff --git a/resources/lang/id/couple.php b/resources/lang/id/couple.php new file mode 100644 index 0000000..c92334f --- /dev/null +++ b/resources/lang/id/couple.php @@ -0,0 +1,14 @@ + 'Lhat Profil Pernikahan', + 'childs_count' => 'Jumlah Anak', + 'grand_childs_count' => 'Jumlah Cucu', + + // Attributes + 'husband' => 'Kepala Keluarga', + 'wive' => 'Isteri', + 'marriage_date' => 'Tanggal Pernikahan', + 'divorce_date' => 'Tanggal Perceraian', +]; \ No newline at end of file diff --git a/resources/lang/id/user.php b/resources/lang/id/user.php index d752764..87d3ed0 100644 --- a/resources/lang/id/user.php +++ b/resources/lang/id/user.php @@ -16,6 +16,7 @@ return [ 'grand_mother' => 'Nenek', 'grand_father' => 'Kakek', 'nieces' => 'Keponakan', + 'marriages' => 'Pernikahan', // Actions 'edit' => 'Edit Profil', diff --git a/resources/views/users/marriages.blade.php b/resources/views/users/marriages.blade.php new file mode 100644 index 0000000..755ef60 --- /dev/null +++ b/resources/views/users/marriages.blade.php @@ -0,0 +1,29 @@ +@extends('layouts.app') + +@section('content') +
| {{ trans('couple.husband') }} | {{ $marriage->husband->profileLink() }} |
|---|---|
| {{ trans('couple.wive') }} | {{ $marriage->wife->profileLink() }} |
| {{ trans('couple.marriage_date') }} | {{ $marriage->marriage_date }} |
| {{ trans('couple.divorce_date') }} | {{ $marriage->divorce_date }} |
| {{ trans('couple.childs_count') }} | {{ $marriage->childs_count }} |
| {{ trans('couple.grand_childs_count') }} | ? |