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.
42 lines
1.1 KiB
42 lines
1.1 KiB
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Appended\Traites\GetDateAttributesTrait;
|
|
use Carbon\Carbon;
|
|
use Carbon\CarbonPeriod;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class CRMEvent extends Model
|
|
{
|
|
public $fillable = ['eventable_id', 'eventable_type', 'title', 'text', 'date' , 'property'];
|
|
protected $table = 'crm_events';
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo('App\User')->select(['id', 'name']);
|
|
}
|
|
|
|
public function getDateAttribute()
|
|
{
|
|
$carbon = new Carbon($this->attributes['date']);
|
|
return $carbon;
|
|
}
|
|
public function setDateAttribute($value)
|
|
{
|
|
$carbon = new Carbon();
|
|
$date = substr($value, 0, -3);
|
|
$date = $carbon->timestamp($date)->timezone('Asia/Tehran')->toDateString();
|
|
$this->attributes['date'] = $date;
|
|
}
|
|
public function setPropertyAttribute($value){
|
|
$this->attributes['property'] = json_encode($value);
|
|
}
|
|
public function getPropertyAttribute(){
|
|
return json_decode($this->attributes['property']);
|
|
}
|
|
public function setUserIdAttribute(){
|
|
$this->attributes['user_id'] = auth()->user()->id;
|
|
}
|
|
}
|