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.8 KiB
99 lines
2.8 KiB
<?php
|
|
|
|
namespace App;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Project extends Model
|
|
{
|
|
protected $fillable = [
|
|
'temp_business_id',
|
|
'project_type',
|
|
'description',
|
|
'begin_date',
|
|
'end_date',
|
|
'special_features'
|
|
];
|
|
|
|
public function responsible_person()
|
|
{
|
|
return $this->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');
|
|
// }
|
|
}
|