Skip to content

Instantly share code, notes, and snippets.

@haltsir
Created December 5, 2024 13:11
Show Gist options
  • Save haltsir/c5da3c0d5502fe707992c74692d0e617 to your computer and use it in GitHub Desktop.
Save haltsir/c5da3c0d5502fe707992c74692d0e617 to your computer and use it in GitHub Desktop.
Laravel AppServiceProvider defaults
<?php
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
$this->configureCommands();
$this->configureDatabase();
$this->configureNetwork();
$this->configureAssets();
}
private function configureCommands(): void
{
DB::prohibitDestructiveCommands(app()->isProduction());
}
private function configureDatabase(): void
{
Model::shouldBeStrict();
if (app()->isLocal()) {
DB::listen(function ($query) {
$bindings = array_map(
fn ($value) => ($value instanceof \DateTime)
? $value->format('Y-m-d H:i:s')
: $query->connection->escape($value),
$query->bindings);
Log::debug(Str::replaceArray('?', $bindings, $query->sql));
});
}
}
private function configureNetwork(): void
{
URL::forceScheme('https');
}
private function configureAssets(): void
{
Vite::useAggressivePrefetching();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment