Disable preventLazyLoading for Nova only #5240
-
Is there any way to properly disable the registered preventLazyLoading for Nova only?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
To do things only during Nova requests, you can use use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Laravel\Nova\Nova;
// Can be done in NovaServiceProvider, AppServiceProvider, or wherever you'd like.
// (As long as it's not too early/late in the process)
Nova::whenServing(
function (): void {
Model::preventLazyLoading(false);
},
function (): void {
Model::preventLazyLoading(App::isLocal());
},
);
// You should also be able to do the below,
// to always run it by default, but 'override' for Nova explicitly.
// Although, I haven't tried this.
Model::preventLazyLoading(App::isLocal());
Nova::whenServing(function (): void {
Model::preventLazyLoading(false);
}); There's an example right above where this links takes you in the documentation: I'm pretty sure I've seen more examples somewhere else in the documentation, but couldn't find it right now. |
Beta Was this translation helpful? Give feedback.
To do things only during Nova requests, you can use
\Laravel\Nova\Nova::whenServing()
.The first argument can be used to do things during Nova requests, and the second argument would be when it's not a Nova request (i.e., should be frontend for non-Nova routes, Artisan commands, etc).