You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.2 KiB
91 lines
2.2 KiB
5 years ago
|
<?php
|
||
|
|
||
|
namespace App;
|
||
|
|
||
|
use Illuminate\Database\Eloquent\Model;
|
||
|
use App\Appended\Traites\GetDateAttributesTrait;
|
||
|
|
||
|
|
||
|
class News extends Model
|
||
|
{
|
||
|
use GetDateAttributesTrait;
|
||
|
|
||
|
public $fillable = ['title_fa', 'body', 'summary'];
|
||
|
|
||
|
public function categories()
|
||
|
{
|
||
|
// return $this->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}";
|
||
|
}
|
||
|
}
|