Skip to content

Instantly share code, notes, and snippets.

@sawirricardo
Last active April 15, 2025 14:42
Show Gist options
  • Save sawirricardo/6e58e1bf528068a88f975a296a7e0e66 to your computer and use it in GitHub Desktop.
Save sawirricardo/6e58e1bf528068a88f975a296a7e0e66 to your computer and use it in GitHub Desktop.
Better defaults for your laravel projects, inspired by Nuno Maduro
<?php
namespace App\Providers;
use Carbon\CarbonImmutable;
use Illuminate\Database\Eloquent\Model;
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;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Model::unguard();
Model::shouldBeStrict();
Model::automaticallyEagerLoadRelationships();
Vite::useAggressivePrefetching();
URL::forceHttps();
DB::prohibitDestructiveCommands(app()->isProduction());
Date::use(CarbonImmutable::class);
Password::defaults(fn (): ?Password => app()->isProduction() ? Password::min(12)->max(255)->uncompromised() : null);
if (app()->runningUnitTests()) {
Http::preventStrayRequests();
Sleep::fake();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment