belongsToMany('App\Category'); return $this->belongsToMany('App\Category', 'category_news', 'news_id', 'category_id'); } public function user_frames() { return $this->morphToMany('App\\SpUserFrame', 'element', 'sp_user_elements'); } public function business() { return $this->belongsTo('App\Business'); // return $this->belongsToMany('App\Category','category_news','news_id','category_id'); } public function files() { return $this->morphMany('App\Upload', 'uploadable')->select('id', 'uploadable_id', 'uploadable_type', 'user_id', 'path'); } public function gallery() { return $this->morphMany('App\Upload', 'uploadable')->where('file_role', 1); } /** * Get all of the post's comments. */ public function comments() { return $this->morphMany('App\Comment', 'commentable'); } public function orginalTitleImage() { return $this->morphToMany('App\Gallery', 'uploadable')->wherePivot('image_role', 'TitleImage')->where('parent_id', null); } public function title_image() { return $this->morphToMany('App\Gallery', 'uploadable')->wherePivot('image_role', 'TitleImage')->where('parent_id', null); } public function images() { return $this->morphToMany('App\Gallery', 'uploadable'); } public function tags() { return $this->morphToMany('App\Tag', 'taggable'); } public function tiny_images() { return $this->morphToMany('App\Gallery', 'uploadable')->wherePivot('image_role', 'TinyImages')->where('parent_id', null); } public function getThumbnailAttribute() { if ($this->title_image->isNotEmpty()) { return $this->title_image->first()->path; } return 'WM-Main/Assets/NoPreview/preview.png'; } public function setDetailLink($value) { $this->linkToDetail = "{$value}/{$this->id}"; } }