From c7612158d44e6077c1b45cf4dfcde39f1dab9112 Mon Sep 17 00:00:00 2001 From: WillTheDeveloper Date: Sun, 25 Sep 2022 22:00:40 +0100 Subject: [PATCH] Added assignment associated users Signed-off-by: WillTheDeveloper --- app/Http/Resources/AssignmentUserResource.php | 18 ++++++++++++++++++ app/Models/Assignment.php | 2 +- routes/api.php | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 app/Http/Resources/AssignmentUserResource.php diff --git a/app/Http/Resources/AssignmentUserResource.php b/app/Http/Resources/AssignmentUserResource.php new file mode 100644 index 00000000..4305fee0 --- /dev/null +++ b/app/Http/Resources/AssignmentUserResource.php @@ -0,0 +1,18 @@ + $this->title, + /*'students' => $this->User->toArray()*/ + ]; + } +} diff --git a/app/Models/Assignment.php b/app/Models/Assignment.php index 22857d72..19d40a87 100644 --- a/app/Models/Assignment.php +++ b/app/Models/Assignment.php @@ -19,7 +19,7 @@ class Assignment extends Model public function User() { - return $this->belongsToMany(User::class)->withPivot('has_seen'); + return $this->belongsToMany(User::class)->withPivot('has_seen', 'user_id'); } public function Group() diff --git a/routes/api.php b/routes/api.php index 3d80e703..6d1da576 100644 --- a/routes/api.php +++ b/routes/api.php @@ -29,4 +29,7 @@ Route::get('/assignment/{id}', function ($id) { return new \App\Http\Resources\AssignmentResource(\App\Models\Assignment::findOrFail($id)); +}); +Route::get('/assignment/{id}/students', function ($id) { + return new \App\Http\Resources\AssignmentUserResource(\App\Models\Assignment::findOrFail($id)); }); \ No newline at end of file