Closed
Description
Laravel Version
12.8.1
PHP Version
8.4.5
Database Driver & Version
8.0.31
Description
After adding the following line to the AppServiceProvider’s boot() method:
`use Illuminate\Database\Eloquent\Model;
public function boot(): void
{
Model::automaticallyEagerLoadRelationships();
}`
an error occurs when trying to cache a model collection or API resource:
Serialization of 'Closure' is not allowed
This happens even when caching plain model collections like:
Cache::remember('key', 3600, fn () => Model::with('relation')->get());
or:
Cache::remember('key', 3600, fn () => MyResource::collection(Model::with('relation')->get())->resolve());
Steps To Reproduce
1. Add Model::automaticallyEagerLoadRelationships(); in your AppServiceProvider::boot()
2. Attempt to cache an Eloquent model collection or API Resource
3. See this error:
Serialization of 'Closure' is not allowed
Metadata
Metadata
Assignees
Labels
No labels