From 42b200766d077d4bec92d463b21187fa2285ad6f Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 12:26:42 +0600 Subject: [PATCH 01/13] T1 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 3d7facd2..b3d27708 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', 'id); } public function comments() From 039a29da30da6a1f6c95f2cf031425a101db5c31 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 12:29:34 +0600 Subject: [PATCH 02/13] T1 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 b3d27708..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, 'users_id', 'id); + return $this->hasMany(Task::class, 'users_id'); } public function comments() From 0807f2bdfa48cfd25790b7a0de1ce9c2a66e129e Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 12:45:32 +0600 Subject: [PATCH 03/13] T2 Update Task.php --- 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..ae6fab21 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 0d60c56150ff19a773fa916973dc0a6c659871de Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 12:57:51 +0600 Subject: [PATCH 04/13] T3 Update User.php --- app/Models/User.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/User.php b/app/Models/User.php index 881d74cc..78cd5bdd 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 + return $this->hasManyThrough(Comment::class, Task::class); } public function projects() From fb2d600b453bd5ab1a0213fae445781dd768fa0e Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 13:02:26 +0600 Subject: [PATCH 05/13] T3 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 78cd5bdd..a5914ce8 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->hasManyThrough(Comment::class, Task::class); + return $this->hasManyThrough(Comment::class, Task::class,'users_id' ); } public function projects() From f290317e07135bb47f5e442819b34575f194075f Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 20:18:30 +0600 Subject: [PATCH 06/13] T4 Update Role.php --- 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..01c7d71e 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 f6e1c2a065ae24c102e107cc1fbbb211d9c0e038 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 20:27:17 +0600 Subject: [PATCH 07/13] T5 Update Team.php --- 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..6fa503ea 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,'team_user'); } } From f55c5c52ec9ffebb12ed4624ed34c5af151dea79 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 20:32:13 +0600 Subject: [PATCH 08/13] T5 Update Team.php --- 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 6fa503ea..cd6a1181 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,'team_user'); + return $this->belongsToMany(User::class,'team_user')->withPivot('position', 'created_at'); } } From 7164cf52b9417d0147db8abef53386fc6b07ed84 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 20:41:18 +0600 Subject: [PATCH 09/13] T6 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 2b9be507..2f86a528 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('teams as teams_avg_size', 'size')->get(); return view('countries.index', compact('countries')); } From 40d7b32a1fd124b93d41e4afeaec51e38927e047 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 20:55:51 +0600 Subject: [PATCH 10/13] T7 Update Attachment.php --- app/Models/Attachment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php index 158b6470..32c47267 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 556cb85eba8f6d690b7bf107e55c5432a07e8575 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 21:03:47 +0600 Subject: [PATCH 11/13] T8 Update ProjectController.php --- app/Http/Controllers/ProjectController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index e04fb1a6..9dd6c12a 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -10,7 +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 - + $user = Auth::user(); + $user->projects()->attach($request->project_id, [ + 'start_date' => $request->start_date + ]); return 'Success'; } } From d1995d2d4c2b07c0e2115ce6c927a1f77dcf8e5d Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 21:05:26 +0600 Subject: [PATCH 12/13] T9 Update UserController.php --- 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 2817b23dd903b8d4df337ec53e60e3b2dde88230 Mon Sep 17 00:00:00 2001 From: Imtyaz Ahmed <54882826+imtyaz-17@users.noreply.github.com> Date: Sat, 6 Jul 2024 21:09:59 +0600 Subject: [PATCH 13/13] T8 Update ProjectController.php --- app/Http/Controllers/ProjectController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 9dd6c12a..ed4a0563 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -10,7 +10,7 @@ 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 - $user = Auth::user(); + $user = auth()->user(); $user->projects()->attach($request->project_id, [ 'start_date' => $request->start_date ]);