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.
99 lines
2.3 KiB
99 lines
2.3 KiB
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Laravel\Scout\Searchable;
|
|
|
|
class Product extends Model
|
|
{
|
|
use Searchable;
|
|
|
|
protected $fillable = ['model_fa', 'model_en', 'rate', 'brand_id', 'slug', 'category_id', 'pros', 'cons', 'user_id'];
|
|
|
|
protected $hidden = [
|
|
'variations',
|
|
];
|
|
|
|
public function detail()
|
|
{
|
|
return $this->belongsTo('App\ProductDetail', 'product_detail_id');
|
|
}
|
|
|
|
public function category()
|
|
{
|
|
return $this->belongsTo('App\Category');
|
|
}
|
|
|
|
public function comments()
|
|
{
|
|
return $this->morphMany('App\Comment', 'commentable');
|
|
}
|
|
|
|
public function feedbacks()
|
|
{
|
|
return $this->morphMany('App\Feedback', 'feedbackable')->orderBy('updated_at', 'desc');
|
|
}
|
|
|
|
|
|
public function brand()
|
|
{
|
|
return $this->belongsTo('App\Brand');
|
|
}
|
|
|
|
|
|
public function tags()
|
|
{
|
|
return $this->morphToMany('App\Tag', 'taggable');
|
|
}
|
|
|
|
public function files()
|
|
{
|
|
return $this->morphToMany('App\Gallery', 'uploadable');
|
|
}
|
|
|
|
public function images()
|
|
{
|
|
return $this->morphToMany('App\Gallery', 'uploadable');
|
|
}
|
|
|
|
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 gallery()
|
|
{
|
|
return $this->morphToMany('App\Gallery', 'uploadable')->wherePivot('image_role', 'Gallery')->where('parent_id', null);
|
|
}
|
|
|
|
public function likes()
|
|
{
|
|
return $this->morphMany('App\Like', 'likeable');
|
|
}
|
|
|
|
public function toSearchableArray()
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'model_en' => $this->model_en,
|
|
'model_fa' => $this->model_fa,
|
|
'description' => $this->description,
|
|
'author_id' => $this->author_id,
|
|
'brand_id' => $this->brand_id,
|
|
'slug' => $this->slug,
|
|
'category_id' => $this->category_id,
|
|
];
|
|
}
|
|
|
|
public function special_content_options()
|
|
{
|
|
return $this->morphMany('App\SpecialContentOption', 'special_content_optionable');
|
|
}
|
|
}
|