updated controllers to use resources
This commit is contained in:
parent
0787b75780
commit
19f81a0024
6 changed files with 79 additions and 18 deletions
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class MovieList extends Model
|
||||
|
|
@ -14,13 +15,30 @@ class MovieList extends Model
|
|||
'slug',
|
||||
];
|
||||
|
||||
protected $with = ['listOwner'];
|
||||
|
||||
public function listOwner(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'owner');
|
||||
}
|
||||
|
||||
public function movies(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Movie::class);
|
||||
}
|
||||
|
||||
public function getUserRole($userId)
|
||||
{
|
||||
return $this->collaborators()
|
||||
->where('user_id', $userId)
|
||||
->first()
|
||||
?->pivot
|
||||
->role;
|
||||
}
|
||||
|
||||
public function collaborators(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'movie_list_user');
|
||||
return $this->belongsToMany(User::class, 'movie_list_user')
|
||||
->withPivot('role');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue