ldc-boutique-cnc-sable/app/Models/Faq.php
2026-10-27 09:58:12 +01:00

45 lines
1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Guarded;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string $question
* @property string $answer
* @property int $order
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*
* @mixin \Eloquent
*/
#[Fillable(['question', 'answer'])]
#[Guarded([
'order',
])]
class Faq extends Model
{
#[\Override]
protected static function booted()
{
static::creating(function (self $model): void {
self::manageFields($model);
});
static::updating(function (self $model): void {
self::manageFields($model);
});
}
private static function manageFields(self $model): void
{
if (is_null($model->order)) {
// @phpstan-ignore argument.type
$model->order = intval(self::query()->max('order'));
}
}
}