From 7e74f346039aef8a2f56167634e8f8c60a0bf4f4 Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:24:23 +0200 Subject: [PATCH 01/12] Task 1 --- app/Models/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index 3d7facd2..881d74cc 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -45,7 +45,7 @@ class User extends Authenticatable public function tasks() { // TASK: fix this by adding a parameter - return $this->hasMany(Task::class); + return $this->hasMany(Task::class, 'users_id'); } public function comments() From ced14947462ce1e487f95dfd91ed2e21d3debf3e Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:27:19 +0200 Subject: [PATCH 02/12] Task 2 --- app/Models/Task.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Task.php b/app/Models/Task.php index 01f6912d..619eea62 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -13,6 +13,6 @@ class Task extends Model public function user() { - return $this->belongsTo(User::class, 'users_id'); + return $this->belongsTo(User::class, 'users_id')->withDefault(); } } From d9529fa18647d365993b9bca1ab075a3f25ec4ff Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:47:07 +0200 Subject: [PATCH 03/12] Task 3 --- app/Models/User.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/User.php b/app/Models/User.php index 881d74cc..acb00159 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -51,6 +51,7 @@ public function tasks() public function comments() { // TASK: add the code here for two-level relationship + returen $this->throughTasks()->hasComments(); } public function projects() From 776c396a467ec3dcef097f224addb78a3107fc06 Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:56:40 +0200 Subject: [PATCH 04/12] Task 4 IDK why --- app/Models/Role.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Role.php b/app/Models/Role.php index c2f3fc89..24099baa 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -14,6 +14,6 @@ class Role extends Model public function users() { // TASK: fix this by adding a parameter - return $this->belongsToMany(User::class); + return $this->belongsToMany(User::class, 'users_roles'); } } From c8cc51eab00af3cf1baf478a8defc3cbb0709ffc Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:59:12 +0200 Subject: [PATCH 05/12] Task 5 --- app/Models/Team.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Team.php b/app/Models/Team.php index 13969525..c0448b98 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -14,7 +14,7 @@ class Team extends Model public function users() { // TASK: fix this by adding some extra code - return $this->belongsToMany(User::class); + return $this->belongsToMany(User::class)->withPivot('position','created_at'); } } From f2782b5d6f37a6d4602708464fb07aed1b968f1e Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:04:57 +0200 Subject: [PATCH 06/12] Task 6 --- app/Http/Controllers/CountryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/CountryController.php b/app/Http/Controllers/CountryController.php index 2b9be507..6c461f95 100644 --- a/app/Http/Controllers/CountryController.php +++ b/app/Http/Controllers/CountryController.php @@ -9,7 +9,7 @@ class CountryController extends Controller public function index() { // TASK: load the relationship average of team size - $countries = Country::all(); + $countries = Country::withAvg('team','size')-get(); return view('countries.index', compact('countries')); } From 304b06f83f2bc882be02dc69325cdbd8bf990679 Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:09:36 +0200 Subject: [PATCH 07/12] Task 7 --- app/Models/Attachment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php index 158b6470..b899a4c4 100644 --- a/app/Models/Attachment.php +++ b/app/Models/Attachment.php @@ -14,5 +14,6 @@ class Attachment extends Model public function attachable() { // TASK: fill in the code to make it work + return $this->morphTo(); } } From 25a1dbb090c9841cc7e1943550347876f72b0092 Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:19:07 +0200 Subject: [PATCH 08/12] Task 8 --- app/Http/Controllers/ProjectController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index e04fb1a6..0ce2981b 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -10,6 +10,10 @@ public function store(Request $request) { // TASK: Add one sentence to save the project to the logged-in user // by $request->project_id and with $request->start_date parameter + auth()->user()->projects()->attach( + $request->project_id, + ['start_date' => $request->start_date] + ); return 'Success'; } From 0f995f5aca0331c02dd32a8ef6035bccf5c85cec Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:24:40 +0200 Subject: [PATCH 09/12] Task 9 --- app/Http/Controllers/UserController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 7ae1d3d6..b97f4a1c 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -8,7 +8,7 @@ class UserController extends Controller { public function index() { - $users = User::all(); + $users = User::has('projects')->get(); return view('users.index', compact('users')); } From 1602a3e055edab3eaa611225c7e52c8577b3e87e Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:30:42 +0200 Subject: [PATCH 10/12] Update User.php --- app/Models/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index acb00159..e92c88c5 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -51,7 +51,7 @@ public function tasks() public function comments() { // TASK: add the code here for two-level relationship - returen $this->throughTasks()->hasComments(); + return $this->throughTasks()->hasComments(); } public function projects() From c59bf90c6e3335acc8515d121e325caee6d7b726 Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:34:11 +0200 Subject: [PATCH 11/12] Update CountryController.php --- app/Http/Controllers/CountryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/CountryController.php b/app/Http/Controllers/CountryController.php index 6c461f95..49e68134 100644 --- a/app/Http/Controllers/CountryController.php +++ b/app/Http/Controllers/CountryController.php @@ -9,7 +9,7 @@ class CountryController extends Controller public function index() { // TASK: load the relationship average of team size - $countries = Country::withAvg('team','size')-get(); + $countries = Country::withAvg('teams','size')->get(); return view('countries.index', compact('countries')); } From 20c61ef1f2671950b184dd3a969aeedb97d79db7 Mon Sep 17 00:00:00 2001 From: Ahmad Essam <72272968+ahmadessam5@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:37:14 +0200 Subject: [PATCH 12/12] Update User.php --- app/Models/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index e92c88c5..73b0af22 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -51,7 +51,7 @@ public function tasks() public function comments() { // TASK: add the code here for two-level relationship - return $this->throughTasks()->hasComments(); + return $this->hasManyThrough(Comment::class, Task::class); } public function projects()