Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3k stars 880 forks source link

[Bug] In case of disabled lazy load eager load relation query on update #5520

Open gaborfarkas0211 opened 1 month ago

gaborfarkas0211 commented 1 month ago

Bug report

What I did

Lazy load is disabled in my project. I have a repeatable field using a hasMany relation on create and update. In the setup, I eager load the required relations for operations. I created an entry with the hasMany relation using the repeatable field. When I tried to update, the edit action gave me an error: Attempted to lazy load [relation] on model [model] but lazy loading is disabled.

What I expected to happen

The relations are loaded and the repeatable field is filled on update.

What happened

I have got the $entry property on CrudPanel without relations. The UpdateOperation edit's action checks the access to the given model. That means the CrudPanel's Access trait will set the $entry property using 'getModelWithCrudPanelQuery' query. After that the $entry property is set and the custom query will not used.

What I've already tried to fix it

There is no way for me to fix it unless I override the UpdateOperation's edit action in my project.

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud the bug... is it still there?

Yes

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

8.3.4

LARAVEL VERSION:

11.7.0.0

BACKPACK PACKAGE VERSIONS:

backpack/crud: 6.7.12 backpack/pro: 2.2.0

pxpm commented 1 month ago

Hey @gaborfarkas0211 thanks for the report.

It's an issue that we are aware, unfortunately it's a BC to introduce and we missed the opportunity to do it in v6 sadly :(

Please fix it on your side for the moment, an easy way would be to create a copy of the update operation trait to your app and call it UpdateEagerLoadOperation, do the changes you need there. That way you don't polute your crud controller with overrides, and next version when we fix it, you just search and replace your custom operation for the backpack fixed one and you are golden.

Let me know if that helps.

Cheers