ActivityType::class, 'model_lie' => CellModel::class ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'date' => 'date', ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'user_id', 'date', 'slot', 'activity', 'description', 'id_lie', 'model_lie' ]; // * RELATIONSHIPS /** * BelongsTo User relation * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function user() { return $this->belongsTo(User::class); } /** * relationship to linked objet * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function relatedModel() { switch ($this->model_lie) { case 'sites': return $this->belongsTo(Site::class, 'id_lie'); case 'projects': return $this->belongsTo(Project::class, 'id_lie'); case 'tickets': return $this->belongsTo(Ticket::class, 'id_lie'); default: return new BelongsTo($this->newQuery(), $this, '', '', ''); } } }