validation.required error after update filament

Hey guys i have an error after update, i check all my code and at the moment all look ok... i don't see any problem, however in the front, in the form i receive the error message validation.required. and example of this is a toggle here is my migration
public function up(): void
{
Schema::create('schedules', function (Blueprint $table) {
$table->id();
$table->foreignId('business_id')->constrained('businesses')->onDelete('cascade'); // Relación con el negocio
$table->string('name');
$table->json('days_of_week'); // Almacena múltiples días de la semana
$table->json('time_ranges'); // Almacenamos los rangos de horarios
$table->boolean('is_closed')->default(false);
$table->timestamps();
});
}
public function up(): void
{
Schema::create('schedules', function (Blueprint $table) {
$table->id();
$table->foreignId('business_id')->constrained('businesses')->onDelete('cascade'); // Relación con el negocio
$table->string('name');
$table->json('days_of_week'); // Almacena múltiples días de la semana
$table->json('time_ranges'); // Almacenamos los rangos de horarios
$table->boolean('is_closed')->default(false);
$table->timestamps();
});
}
here is my fillable in the model
protected $fillable = [
'name',
'time_ranges',
'is_closed',
];
protected $fillable = [
'name',
'time_ranges',
'is_closed',
];
and here is my Toogle in my form
Forms\Components\Toggle::make('is_closed')
->label('¿Está cerrado?')
->default(false)
->dehydrated(true)
//->required(),
Forms\Components\Toggle::make('is_closed')
->label('¿Está cerrado?')
->default(false)
->dehydrated(true)
//->required(),
however i have this error when i try to save the data
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'is_closed' cannot be null (Connection: mysql, SQL: insert into `schedules` (`name`, `time_ranges`, `is_closed`, `business_id`, `updated_at`, `created_at`) values (Corte de pelo, [{"apply_to_days":["0","1"],"opening_time":"08:00:00","closing_time":"09:15:00"}], ?, 1, 2025-05-07 19:43:08, 2025-05-07 19:43:08))
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'is_closed' cannot be null (Connection: mysql, SQL: insert into `schedules` (`name`, `time_ranges`, `is_closed`, `business_id`, `updated_at`, `created_at`) values (Corte de pelo, [{"apply_to_days":["0","1"],"opening_time":"08:00:00","closing_time":"09:15:00"}], ?, 1, 2025-05-07 19:43:08, 2025-05-07 19:43:08))
No description
Solution:
Yesterday I had the same problem then and applied as a solution to use cluster, I have a form in which I add or create new categories of services but I got a similar error ... then I checked, checked, found out, used AI, and nothing, it only occurred to me to jump to create the category in a model and resource apart and from there call it in the other resource, but now I see that it persisted in another resource, well the one we saw now ... It is strange if on the one hand because this has not h...
Jump to solution
84 Replies
charlie
charlie2d ago
maybe try with ->default('0')
TranceCode
TranceCodeOP2d ago
no, i have the same error! i clear config:clear view:clear cache:clear
No description
TranceCode
TranceCodeOP2d ago
and the problem is the same!
charlie
charlie2d ago
Can you show the entire form?
TranceCode
TranceCodeOP2d ago
he is the full file bro!
charlie
charlie2d ago
seems fine to me... try to cast is_closed as boolean?
TranceCode
TranceCodeOP2d ago
Yes, I had also done it before but it didn't solve anything either. 👀 😓
charlie
charlie2d ago
sorry, I don't know
TranceCode
TranceCodeOP2d ago
don't worry bro, i will fix that... Thanks you
charlie
charlie2d ago
oh I see in your code ->default(0) but I think it should be a string: ->default("0") because states are strings in Filament
TranceCode
TranceCodeOP2d ago
mmm maybe my problem was that i execute
composer update
composer update
but i forgot the
php artisan filament>upgrade
php artisan filament>upgrade
charlie
charlie2d ago
but wait, do you have the same error if the toggle is on?
TranceCode
TranceCodeOP2d ago
yeah, same error if is true or false, or default, i try with a checkbox and the problem was the same!
charlie
charlie2d ago
THAT's weird. don't you have a mutateBeforeSaveOrSomething method in create or edit page that mutate your data?
TranceCode
TranceCodeOP2d ago
no, nothing in create and edit pages
charlie
charlie2d ago
and no mutator in your model, I guess?
TranceCode
TranceCodeOP2d ago
protected $casts = [
'days_of_week' => 'array', // Convertimos el JSON en un arreglo automáticamente
'time_ranges' => 'array', // Convertimos el JSON en un arreglo automáticamente
'is_closed' => 'boolean'
];
protected $casts = [
'days_of_week' => 'array', // Convertimos el JSON en un arreglo automáticamente
'time_ranges' => 'array', // Convertimos el JSON en un arreglo automáticamente
'is_closed' => 'boolean'
];
TranceCode
TranceCodeOP2d ago
here is the model
charlie
charlie2d ago
what the hell...
TranceCode
TranceCodeOP2d ago
🤣 😂 so so weird...
awcodes
awcodes2d ago
For starters you can’t require a Boolean it’s always going to be true or false. Also try ->default(false) As long as it’s cast correctly it should just work. Only other thing I can think of is if the views are published and there was an update to them in filament. Looking at the toggle code though, the default is already false too
charlie
charlie2d ago
@awcodes apparently it fails even if the toggle is on, or with a checkbox, so it's not because of the default value
awcodes
awcodes2d ago
Checkbox’s can be null ie off will be null, that’s how checkboxes work in forms. Either their value exists or doesn’t in the form data. The toggle is Boolean though. But that’s why I said to try the default() with false instead of the 0, it might be confusing the state and making it indeterminate. Or just drop the default since it’s already false
charlie
charlie2d ago
it seems it's null in every cases
TranceCode
TranceCodeOP2d ago
i try adding a default value, without a default value... with checkbox and the problem or error is the same!
awcodes
awcodes2d ago
Can you run php artisan about and show me the filament section? On my phone so I can’t look at the files right now.
TranceCode
TranceCodeOP2d ago
how aver if send like a true i receive the same error
No description
charlie
charlie2d ago
try with a TextInput, and writing in it: is it still null?
TranceCode
TranceCodeOP2d ago
No description
TranceCode
TranceCodeOP2d ago
good idea just for test yeah using a TextInput and sending a '0' like value save without problem!
TranceCode
TranceCodeOP2d ago
charlie
charlie2d ago
And do you confirm a simple Toggle gives null?
Forms\Components\Toggle::make('is_closed'),
Forms\Components\Toggle::make('is_closed'),
with no default, dehydrated, or required method
awcodes
awcodes2d ago
Is there any other fields in the form that could be $setting the state with a live, etc
TranceCode
TranceCodeOP2d ago
No description
TranceCode
TranceCodeOP2d ago
mmm
TranceCode
TranceCodeOP2d ago
maybe the select in users or the Repeater Component when i add a range of time??
charlie
charlie2d ago
To be sure, just keep your toggle, remove the rest of the fields and dd($data) into mutateFormDataBeforeCreate() method in create file like so:
protected function mutateFormDataBeforeCreate(array $data): array
{
dd($data);
}
protected function mutateFormDataBeforeCreate(array $data): array
{
dd($data);
}
that was my last attempt, good night and good luck! 🙂
TranceCode
TranceCodeOP2d ago
No description
TranceCode
TranceCodeOP2d ago
Thank you bro, good night there!
awcodes
awcodes2d ago
I’m not seeing anything unusual in your code. Possibly a caching issue?
charlie
charlie2d ago
you didn't remove the other fields 😉 (just to be sure nothing alter the state)
TranceCode
TranceCodeOP2d ago
No description
TranceCode
TranceCodeOP2d ago
No description
TranceCode
TranceCodeOP2d ago
i clear the cache, restart Docker, delete the binary of laravel octane using frankenphp... i use frankenphp and laravel octane for test my project but this is not a problem... i code with laravel octane more than 3 or 4 months and is the first time that i have this error... can't understand bro
awcodes
awcodes2d ago
Yea, not adding up to me either, if you have a repo you can share I can pull it down and try it on my machine to see if it’s an octane thing or not.
TranceCode
TranceCodeOP2d ago
I don't think it's a problem with the cache either, since using textinput and sending the value as 0 or 1 didn't give me any problems! It saved without any problems!
awcodes
awcodes2d ago
On the toggle can you try: ->dehydrateStateUsing(fn($state) => dd($state)) and see if it’s null there.
charlie
charlie2d ago
I don't think it's Octane. In my opinion it's happening somewhere between Alpine and livewire
TranceCode
TranceCodeOP2d ago
Nothing bro, same problem!
No description
awcodes
awcodes2d ago
Certainly could be a bug, but just trying to figure it out. 😀 there is a canFixIndistinctState on when in a repeater which is the only place in the filament code possibly setting it to null. But typically you have to opt into that behavior.
charlie
charlie2d ago
I would try to dd in afterStateUpdated with live() to see if the value is even changed
awcodes
awcodes2d ago
Good suggestion. But it should be false out of the gate. Any console errors?
TranceCode
TranceCodeOP2d ago
yeah
TranceCode
TranceCodeOP2d ago
No description
TranceCode
TranceCodeOP2d ago
Click to create from list page and error! 🤷‍♂️ 😅 😓
No description
TranceCode
TranceCodeOP2d ago
TranceCode
TranceCodeOP2d ago
Checking the other components the problem persists and is the same.
awcodes
awcodes2d ago
Hmm, that implies to me that they aren’t being returned with the model
TranceCode
TranceCodeOP2d ago
No description
awcodes
awcodes2d ago
Yea, that’s odd.
TranceCode
TranceCodeOP2d ago
livewire.js?id=df3a17f2:3910 Livewire Entangle Error: Livewire property ['data.category_id'] cannot be found on component: ['app.filament.clusters.service-category.resources.service-resource.pages.create-service'] Apparently it goes beyond just the problem with the Toggle
awcodes
awcodes2d ago
Add parent::mount() inside your CreateService mount() function.
TranceCode
TranceCodeOP2d ago
cool now return me a false or if i send a true in toggle
TranceCode
TranceCodeOP2d ago
No description
TranceCode
TranceCodeOP2d ago
the code is like this
<?php

namespace App\Filament\Resources\ScheduleResource\Pages;

use App\Filament\Resources\ScheduleResource;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Auth;

class CreateSchedule extends CreateRecord
{
protected static string $resource = ScheduleResource::class;

protected static bool $canCreateAnother = false;

public function mount(): void
{
parent::mount();

$user = Auth::user();

// Verificar si el usuario no tiene un negocio y no es admin
if (! $user->hasRole('Admin') && $user->businesses->isEmpty()) {
Notification::make()
->title('Acceso denegado')
->body('Debes crear un negocio antes de poder crear un horario')
->danger()
->persistent()
->send();

// redireccionar al listado
redirect()->route('filament.admin.resources.schedules.index');
}
}
}
<?php

namespace App\Filament\Resources\ScheduleResource\Pages;

use App\Filament\Resources\ScheduleResource;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Auth;

class CreateSchedule extends CreateRecord
{
protected static string $resource = ScheduleResource::class;

protected static bool $canCreateAnother = false;

public function mount(): void
{
parent::mount();

$user = Auth::user();

// Verificar si el usuario no tiene un negocio y no es admin
if (! $user->hasRole('Admin') && $user->businesses->isEmpty()) {
Notification::make()
->title('Acceso denegado')
->body('Debes crear un negocio antes de poder crear un horario')
->danger()
->persistent()
->send();

// redireccionar al listado
redirect()->route('filament.admin.resources.schedules.index');
}
}
}
awcodes
awcodes2d ago
Should fix the other errors too.
TranceCode
TranceCodeOP2d ago
yes
charlie
charlie2d ago
That's why you have the :fi: in your name! well done.
TranceCode
TranceCodeOP2d ago
yes, it's working addding the parent::mount();
awcodes
awcodes2d ago
Any time you override the mount method you need to also call the parent mount method because it has $this->form->fill() which runs the setup for all the form fields. That’s why it works. FYI.
TranceCode
TranceCodeOP2d ago
Thank you so much friends, thank you for your time and kindness for help me with this problem...
awcodes
awcodes2d ago
Thank you for being patient with all the back and forth. Took me a minute to see it.
TranceCode
TranceCodeOP2d ago
so, this problem is only because i add the mount() method in my create page?
awcodes
awcodes2d ago
Yep.
charlie
charlie2d ago
took me 2 hours to not see it 😄
TranceCode
TranceCodeOP2d ago
Aaah ok ok, now understand...
awcodes
awcodes2d ago
It’s ok to override if it’s needed, but the parent does other things too, so if you don’t call it from the override those things will never happen unless you also manually implement them in your override.
awcodes
awcodes2d ago
GitHub
filament/packages/panels/src/Resources/Pages/CreateRecord.php at 3....
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Solution
TranceCode
TranceCode2d ago
Yesterday I had the same problem then and applied as a solution to use cluster, I have a form in which I add or create new categories of services but I got a similar error ... then I checked, checked, found out, used AI, and nothing, it only occurred to me to jump to create the category in a model and resource apart and from there call it in the other resource, but now I see that it persisted in another resource, well the one we saw now ... It is strange if on the one hand because this has not happened to me for weeks, until now after having it working for weeks hahahaha maybe the update I did a few days ago deleted cache or something ... I don't know, very strange at the time, but now it is understood why!
TranceCode
TranceCodeOP2d ago
i will check all the project and add this parent::
awcodes
awcodes2d ago
Yea. It’s only needed if you’re extending a livewire component like CreateRecord, EditRecord, etc. Any Page in filament is the livewire component, so if you’re overriding mount then you want to be sure to call the parent method too. Unless you are completely overriding it. It’s also just how OOP works and not necessarily a filament thing or construct.
TranceCode
TranceCodeOP2d ago
Understand, thank you so much for the explanation @awcodes
awcodes
awcodes2d ago
Just glad we figured it out. Now get it shipped. Cheers.🍻

Did you find this page helpful?