Allow reorderable without fillable column?
Good evening everyone!
I am somewhat stuck on adding reorderable. I noticed that I am required to add the
sort
column in my fillable property.
However, normally I use guarded only. The catch is if I only add the sort to the fillable the whole form does not work.
Has somebody else had the same issue and if so did you resolve it or did you add all fillable columns?
I really don't want to add them all😅Solution:Jump to solution
Looks like Filament is using Eloquent's
update([])
... in which Laravel requires the sort field to be unguarded/fillable:
https://github.com/filamentphp/filament/blob/3.x/packages/tables/src/Concerns/CanReorderRecords.php...GitHub
filament/packages/tables/src/Concerns/CanReorderRecords.php at 3.x ...
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
7 Replies
Solution
Looks like Filament is using Eloquent's
update([])
... in which Laravel requires the sort field to be unguarded/fillable:
https://github.com/filamentphp/filament/blob/3.x/packages/tables/src/Concerns/CanReorderRecords.phpGitHub
filament/packages/tables/src/Concerns/CanReorderRecords.php at 3.x ...
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
Using only the
$guarded
does not work unfortunately. I fixed it for now using fillable.
Normally guarded should be enough if I am correct.What do you have
$guarded
set to?Sorry for the late answer! But I had set it to
[]
so in theory that should be enough.
However, the re-order button does not appear.Hm, ya, that's interesting.
(I was puzzled when you said "guarded" when you meant "ungarded" because of
$guarded = [];
😄 )
I wonder if there's someplace in Eloquent core that looks for the $filled
array explicitly despite $guarded
being set to empty array.
... cuz I would have expected the same as you did.
Wait ... maybe $guarded = [];
in each model is treated differently than setting Model::unguard();
globally in an AppServiceProvider.Good morning!
Not sure but it appears that it should do the same when I am looking at it.
The main thing is that normally when I run an
update
query and use protected $guarded = []
it will work.
It feels like there is more happening in filament itself somehow.
However the source code that you shared did not show weird behaviour.Ya, I don't see anything obviously problematic there.