Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DerAndi's avatar

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

0 likes
3 replies
Snapey's avatar

never seen that in any of my projects in any laravel version

DerAndi's avatar

@Snapey This is really interesting. Thanks! So I need to switch to $fillable... :(

Please or to participate in this conversation.