From 2d0dd50063d8f75a488d6f6cff5502ae3a70ab01 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:45:49 +0100 Subject: [PATCH] chore: add strict AppServiceProvider --- app/Providers/AppServiceProvider.php | 101 ++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 8d851577b..0a99bd20f 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -1,10 +1,22 @@ configureHttps(); + $this->configurePasswordValidation(); + $this->configureCommands(); + $this->configureModels(); + $this->configureDates(); + $this->configureRequestExceptions(); + $this->configureVite(); + } + + /** + * Configure HTTPS for production. + */ + private function configureHttps(): void + { + if (App::isProduction() && (bool) config('app.force_https')) { + URL::forceScheme('https'); + } + } + + /** + * Configure password validation for production. + */ + private function configurePasswordValidation(): void + { + if (App::isProduction()) { + Password::defaults(fn () => Password::min(12) + ->letters() + ->mixedCase() + ->numbers() + ->symbols() + ->uncompromised()); + } + } + + /** + * Configure commands for production. + */ + private function configureCommands(): void + { + if (App::isProduction()) { + DB::prohibitDestructiveCommands(); + } + } + + /** + * Configure models. + */ + private function configureModels(): void + { + if (! App::isProduction()) { + Model::preventLazyLoading(); + } + + Model::preventAccessingMissingAttributes(); + Model::unguard(); + + Relation::enforceMorphMap([ + // Add you polymorphic relations here. For example: + // 'application' => \App\Models\Application::class, + ]); + } + + /** + * Configure dates. + */ + private function configureDates(): void + { + Date::use(CarbonImmutable::class); + } + + /** + * Configure request exceptions. + */ + private function configureRequestExceptions(): void + { + if (! App::isProduction()) { + RequestException::dontTruncate(); + } + } + + /** + * Configure Vite for better performance. + */ + private function configureVite(): void + { + Vite::useAggressivePrefetching(); } }