*/ 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. */ protected static function booted(): void { static::creating(function (self $model) { self::setOrder($model); }); } // * METHODS /** * Set order after the last element of the list. */ private static function setOrder(self $model): void { $model->order = \intval(self::query()->max('order')) + 1; } // * RELATIONSHIPS /** * Get the news club for the survey answer. */ public function newsClub(): BelongsTo { return $this->belongsTo(NewsClub::class, 'news_club_id'); } }