belongsToMany('App\User')->wherePivot('type', 'Responsible'); } public function marketer() { return $this->belongsToMany('App\User')->wherePivot('type', 'Marketer'); } public function users() { return $this->belongsToMany('App\User'); } public function temp_business() { return $this->belongsTo('App\TempBusiness', 'temp_business_id', 'id')->select(['id', 'brand_fa', 'brand_en', 'details', 'phones', 'created_at', 'business_id']); } public function comments() { return $this->morphMany('App\Comment', 'commentable')->with('user')->select(["id", "text", "commentable_id", "commentable_type", "user_id", "created_at"]); } public function Events() { return $this->morphMany('App\CrmEvent', 'eventable')->with('user') ->select(["id", "title", "text", "date", "user_id" ,"property", "created_at"]); } public function images() { return $this->morphToMany('App\Gallery', 'uploadable'); } public function gallery() { return $this->morphToMany('App\Gallery', 'uploadable')->wherePivot('image_role', 'Gallery')->where('parent_id', null); } public function setSpecialFeaturesAttribute($value) { $this->attributes['special_features'] = json_encode($value, JSON_UNESCAPED_UNICODE); } public function getSpecialFeaturesAttribute() { return json_decode($this->attributes['special_features']); } public function setBeginDateAttribute($value) { $carbon = new Carbon(); $date = substr($value, 0, -3); $date = $carbon->timestamp($date)->timezone('Asia/Tehran')->toDateString(); $this->attributes['begin_date'] = $date; } public function setEndDateAttribute($value) { if (!is_null($value)){ $carbon = new Carbon(); $date = substr($value, 0, -3); $date = $carbon->timestamp($date)->timezone('Asia/Tehran')->toDateString(); $this->attributes['end_date'] = $date; }else{ $this->attributes['end_date'] = $value; } } // public function getBeginDateAttribute() // { // return jdate( $this->attributes['begin_date'])->format('y/m/d').' | '.jdate( $this->attributes['begin_date']) // ->ago(); // } // public function getEndDateAttribute() // { // return jdate( $this->attributes['end_date'])->format('y/m/d'); // } }