id; if($this->users()->where('id', $userId)->first()){ return true; }else{ return false; } } /** * Get media linked */ public function getMediacountAttribute() { $userId = Auth::user()->id; if($this->parent_id != 1 && $this->id != 1){ // dossier classic return $this->medias() ->where(function ($query) use ( $userId ) { $query->where('statut', '<>', config('services.statut.brouillon')) ->orWhere('created_by', $userId); }) ->count(); }else{ // dossier dépôt return $this->medias()->count(); } } /** * The marques that belong to the dossier. */ public function marques() { return $this->belongsToMany('App\Marque', 'marques_dossiers', 'dossier_id', 'marque_id'); } /** * Get the sujet that owns the dossier. */ public function sujet() { return $this->belongsTo('App\Sujet', 'sujet_id'); } /** * Get the dossier for the sujet. */ public function medias() { return $this->hasMany('App\Media', 'dossier_id', 'id'); } /** * Get the dossiers for the parent. */ public function sousdossiers() { return $this->hasMany('App\Dossier', 'parent_id'); } /** * Get the parent that owns the dossiers. */ public function dossierParent() { return $this->belongsTo('App\Dossier', 'id', 'parent_id'); } /** * The users that belong to the dossier. */ public function users() { return $this->belongsToMany('App\User', 'dossiers_users', 'dossier_id', 'user_id'); } public static function getDossierBySujetid($sujetId) { return Dossier::where('sujet_id', $sujetId)->whereNull('parent_id')->get(); } }