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.
willaengine/app/BusinessItem.php

187 lines
4.4 KiB

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
//use Conner\Tagging\Taggable;
use App\Appended\Traites\GetDateAttributesTrait;
class BusinessItem extends Model
{
// use Taggable;
use GetDateAttributesTrait;
protected $appends = ['image_path'];
protected $fillable = [
'status',///???
'description',
'rate',//????
'price',//???
'price_2',//???
'category_id',
'business_id',//????
'user_id',//???
'brand_id',
'city_id',
'district_id',
'product_id',
'name',
'sale_type',
'used',//???
'thumbnail',
'details',
'title',//???
'verification'//???
];
public function category()
{
return $this->belongsTo('App\Category');
}
public function brand()
{
return $this->belongsTo('App\Brand');
}
public function city()
{
return $this->belongsTo('App\City');
}
public function district()
{
return $this->belongsTo('App\District');
}
public function business()
{
return $this->belongsTo('App\Business');
}
public function product()
{
return $this->belongsTo('App\Product');
}
public function comments()
{
return $this->morphMany('App\Comment', 'commentable');
}
public function feedbacks()
{
return $this->morphMany('App\Feedback', 'feedbackable')->orderBy('updated_at', 'desc');
}
public function offer()
{
return $this->hasMany('App\Offer');
}
public function first_variation()
{
return $this->hasOne('App\BusinessItemVariation');
}
public function business_item_variations()
{
return $this->hasMany('App\BusinessItemVariation');
}
public function user_frames()
{
return $this->morphToMany('App\\SpUserFrame', 'element', 'sp_user_elements');
}
public function user()
{
return $this->belongsTo('App\User');
}
public function tags()
{
return $this->morphToMany('App\Tag', 'taggable');
}
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 gifts()
{
return $this->hasMany('App\Gift', 'business_item_self_id');
}
public function special_content_options()
{
return $this->morphMany('App\SpecialContentOption', 'special_content_optionable');
}
public function getDescriptionAttribute()
{
if ($this->product && $this->product->detail && $this->product->detail->description) {
return $this->product->detail->description . "\n" . $this->attributes['description'];
} else {
return $this->attributes['description'];
}
}
public function getThumbnailAttribute()
{
if ($this->title_image->isNotEmpty()) {
return $this->title_image->first()->path;
} elseif ($this->product() && $this->product && $this->product->title_image->first()) {
return $this->product->title_image->first()->path;
}
return 'WM-Main/Assets/NoPreview/preview.png';
}
public function getImagePathAttribute()
{
if ($this->title_image->isNotEmpty()) {
return $this->title_image->first()->path;
} elseif ($this->product() && $this->product && $this->product->title_image->first()) {
return $this->product->title_image->first()->path;
}
return 'WM-Main/Assets/NoPreview/preview.png';
}
public function setDetailLink($value)
{
$this->linkToDetail = "{$value}/{$this->id}";
}
public function options()
{
return $this->belongsToMany('App\Option');
}
}