*/ protected $fillable = [ 'news_club_id', 'order', 'published', 'answer', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'published' => 'boolean', ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted(): void { static::creating(function (self $model) { self::setOrder($model); }); } // * METHODS /** * Set order after the last element of the list. * * @param self $model * @return void */ private static function setOrder(self $model): void { $model->order = \intval(self::query()->max('order')) + 1; } // * RELATIONSHIPS /** * Get the news club for the survey answer. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function newsClub(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(NewsClub::class, 'news_club_id'); } }