*/ protected $fillable = [ 'day', 'slot' ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ ]; /** * Get the user that owns the schedule slot. */ public function user(): BelongsTo { return $this->belongsTo(User::class); } protected static function defAttr($messages, $attribute){ if(isset($messages[$attribute])){ return $messages[$attribute]; } $attributes = [ "user" => auth()->id(), ]; return $attributes[$attribute]; } protected static function booted() { static::creating(function ($messages) { $messages->user = self::defAttr($messages, "user"); }); } }