never seen that in any of my projects in any laravel version
Why does the $guarded attribute fire a additional select query
Hey Folks,
During some performance optimizations, I noticed that update and insert statements via Eloquent trigger an additional query : "select column_name as column_name from information_schema.columns where table_schema = 'xxxx' and table_name = 'yyyy'"
After some research I found this github issue post for the package "laravel-permissions": https://github.com/spatie/laravel-permission/issues/1569
The same problem was mentioned there, but specifically for this package. I don't use the package, but as a user says, this is due to the use of the "$guarded" attribute. If you remove this or just pass an empty array, the extra select disappears. I tested it and yes the query isn't fired anymore.
However, you need this attribute or the "$fillable" attribute. But to be honest, I don't wan to always entering all column names in $fillable".
My question is: is this normal? Is there a solution for this?
Thanks
Andi
this explains it better. I guess in all my projects, I use $fillable or empty $guarded
https://blog.laravel.com/security-release-laravel-61835-7240
Please or to participate in this conversation.