Created
December 5, 2024 13:11
-
-
Save haltsir/c5da3c0d5502fe707992c74692d0e617 to your computer and use it in GitHub Desktop.
Laravel AppServiceProvider defaults
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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