moved roles to a separate database and added code to make updates
This commit is contained in:
parent
985f339725
commit
836ef8f1f6
14 changed files with 317 additions and 21 deletions
|
|
@ -2,10 +2,23 @@
|
|||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\User;
|
||||
use Auth;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property bool $is_public
|
||||
* @property int $owner
|
||||
* @property User $listOwner
|
||||
* @property Collection $collaborators
|
||||
* @property Collection $movies
|
||||
*
|
||||
* @method string|null getUserRole(int $user_id)
|
||||
*/
|
||||
class MovieListResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
|
|
@ -23,9 +36,10 @@ class MovieListResource extends JsonResource
|
|||
'is_public' => $this->is_public,
|
||||
'owner' => $this->listOwner->username,
|
||||
'role' => $this->getRole($this->owner, $user_id),
|
||||
'collaborators' => $this->whenLoaded('collaborators', fn () => $this->collaborators->map(fn ($user) => [
|
||||
'collaborators' => $this->whenLoaded('collaborators', fn () => $this->collaborators->map(fn (User $user) => [
|
||||
'id' => $user->getKey(),
|
||||
'username' => $user->username,
|
||||
'role' => $user->pivot->role,
|
||||
'role' => $user->pivot->getAttribute('role_id'),
|
||||
])),
|
||||
'movies' => $this->whenLoaded('movies'),
|
||||
];
|
||||
|
|
@ -34,7 +48,7 @@ class MovieListResource extends JsonResource
|
|||
private function getRole(int $owner_id, int $user_id): ?string
|
||||
{
|
||||
if ($owner_id === $user_id) {
|
||||
return 'owner';
|
||||
return 'OWNER';
|
||||
}
|
||||
|
||||
return $this->getUserRole($user_id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue