Z3d0X / filament-fabricator

Block-Based Page Builder Skeleton for your Filament Apps
https://filamentphp.com/plugins/fabricator
MIT License
252 stars 48 forks source link

Lazy loading violation on Subpages in strict mode #77

Closed elopezmo closed 9 months ago

elopezmo commented 1 year ago

Description

A common practice in laravel applications is to have Model::shouldBeStrict() checks active in non-prod environments: https://laravel.com/docs/10.x/eloquent#configuring-eloquent-strictness. Currently, when strict mode is activated, a LazyLoadingViolationException is thrown in: Z3d0X\FilamentFabricator\FilamentFabricatorManager::setPageUrl() in the line if (filled($page->children)) when attempting to save a SubPage (a page with parent) from the filament admin panel.

Reproduction steps

  1. Activate strict mode by adding Model::shouldBeStrict(); to the boot() function of the AppServiceProvider.php
    public function boot()
    {
        Model::shouldBeStrict(); // should normally only be active in non-prod environments
    }
  2. Create a Page and a Child Page through the filament admin panel. When saving the Child Page, the Exception will be thrown

Further comments:

The error does not happen if the line if (filled($page->children)) is replaced with if ($page->children()->count() > 0 && filled($page->children)), which seems to suggest that the Violation is not - strictly speaking - a lazy loading violation, but a missing attribute call violation.

Z3d0X commented 1 year ago

I believe is it is eagerly loaded (last addressed in https://github.com/Z3d0X/filament-fabricator/pull/56). Nevertheless I tried your reproduction steps, I'm unable to reproduce the error. Could you please provide with a reproduction repository, so i could investigate this issue further?

Z3d0X commented 9 months ago

fixed in #96

Released v1.2.1 & v2.0.2 with the fix