mirror of
https://github.com/coollabsio/coolify.git
synced 2026-03-11 08:55:47 +00:00
chore: improve AppServiceProvider
- add automatic eager loading of relationships - configure Laravel Http Facade to prevent stray requests during tests - configure Laravel Sleep Facade to be faked during tests
This commit is contained in:
parent
09ca5040ec
commit
52dab08027
1 changed files with 18 additions and 1 deletions
|
|
@ -11,9 +11,11 @@ use Illuminate\Http\Client\RequestException;
|
|||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Facades\Vite;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Sleep;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
final class AppServiceProvider extends ServiceProvider
|
||||
|
|
@ -33,6 +35,7 @@ final class AppServiceProvider extends ServiceProvider
|
|||
$this->configureCommands();
|
||||
$this->configureModels();
|
||||
$this->configureDates();
|
||||
$this->configureTests();
|
||||
$this->configureRequestExceptions();
|
||||
$this->configureVite();
|
||||
}
|
||||
|
|
@ -77,11 +80,14 @@ final class AppServiceProvider extends ServiceProvider
|
|||
*/
|
||||
private function configureModels(): void
|
||||
{
|
||||
Model::automaticallyEagerLoadRelationships();
|
||||
|
||||
if (! App::isProduction()) {
|
||||
Model::preventLazyLoading();
|
||||
}
|
||||
|
||||
Model::preventSilentlyDiscardingAttributes();
|
||||
Model::preventAccessingMissingAttributes();
|
||||
|
||||
Model::unguard();
|
||||
|
||||
Relation::enforceMorphMap([
|
||||
|
|
@ -98,6 +104,17 @@ final class AppServiceProvider extends ServiceProvider
|
|||
Date::use(CarbonImmutable::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure tests.
|
||||
*/
|
||||
private function configureTests(): void
|
||||
{
|
||||
if (App::runningUnitTests()) {
|
||||
Sleep::fake();
|
||||
Http::preventStrayRequests();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure request exceptions.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue