belongsTo('App\SpTemplate', 'sp_template_id'); } public function user_pages() { return $this->belongsToMany('App\SpUserPage', 'sp_user_frames', 'sp_user_page_id', 'sp_frame_id'); } public function page() { return $this->belongsTo('App\SpPage', 'sp_page_id'); } 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 files() { return $this->morphToMany('App\Gallery', 'uploadable'); } public function frame_type() { return $this->belongsTo('App\SpFrameType', 'sp_frame_type_id'); } public function getThumbnailAttribute() { if ($this->title_image->isNotEmpty()) { return $this->title_image[0]->path; } return 'WM-Main/Assets/NoPreview/preview.png'; } public function getTypeAttribute() { return $this->frame_type->type; } public function scopeSection($query, $frameTypeId, $masterPageId) { return $query->where('sp_page_id', $masterPageId)->where('sp_frame_type_id', $frameTypeId); } public function getFrameInfoAttribute($value) { return json_decode($value, true); } public function setFrameInfoAttribute($value) { $this->attributes['frame_info'] = json_encode($value, JSON_UNESCAPED_UNICODE); } public function users() { return $this->belongsToMany('App\User', 'sp_frame_user')->withPivot('action')->withTimestamps(); } public function user_frames() { return $this->hasMany('App\\SpUserFrame', 'sp_frame_id'); } }