Skip to content

Instantly share code, notes, and snippets.

@rokde
Created December 3, 2024 09:06
Show Gist options
  • Save rokde/e517a9f6ff9ed5815c9e927f54d2f3d1 to your computer and use it in GitHub Desktop.
Save rokde/e517a9f6ff9ed5815c9e927f54d2f3d1 to your computer and use it in GitHub Desktop.
Laravel AppServiceProvider
<?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Vite;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot(): void
{
$this->configureCommands();
$this->configureModels();
$this->configureUrl();
$this->configureVite();
}
/**
* Configure the application's commands.
*/
private function configureCommands(): void
{
DB::prohibitDestructiveCommands(
$this->app->isProduction(),
);
}
/**
* Configure the application's models.
*/
private function configureModels(): void
{
Model::shouldBeStrict();
Model::unguard();
}
/**
* Configure the application's URL.
*/
private function configureUrl(): void
{
URL::forceScheme('https');
}
/**
* Configure the application's Vite.
*/
private function configureVite(): void
{
Vite::usePrefetchStrategy('aggressive');
}
}
@rokde
Copy link
Author

rokde commented Dec 3, 2024

Configure your laravel app in a nice manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment