'boolean' ]; // * RELATIONSHIPS /** * BelongsTo user relation * Get the user that owns the panier. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function owner() { return $this->belongsTo(User::class, 'user_id'); } /** * BelongsToMany users relation * The users that belong to the panier. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function usersFavoris() { return $this->belongsToMany(User::class); } /** * BelongsToMany mediaList relation * The mediaList that belong to the panier. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function mediaList() { return $this->belongsToMany(Media::class, 'panier_media'); } // * GETTERS /** * Get mediacount attribute * * @return boolean */ public function getMediacountAttribute(): int { return $this->mediaList()->count(); } /** * Get mediacover attribute * * @return string */ public function getMediacoverAttribute(): string { $media = $this->mediaList()->whereHas('typeMedia', function ($q) { // * Where type is Photo $q->where('codeTypemedia', 1); })->first(); if ($media) { return $media->thumb_relative_path; } return ''; } }