Every laravel developer I met so far has a standard set of packages and changes after installing a fresh copy of laravel. In this article, I am going to share what I do after installing laravel. Feel free to add your practice in the comment section.
Installation
I recently started using the laravel installer
instead of Composer. It is quite easy and allows one to choose the starter kit at the very beginning of the installation. Which brings us to the topic of starter kit.
Starter Kit
My majority of projects are on inertia/react
, but now I am gradually moving to livewire volt with class
Packages
- Laravel-error-solutions (https://spatie.be/docs/laravel-error-solutions/v1/introduction)
- laravel-schedule-monitor (https://github.com/spatie/laravel-schedule-monitor)
- laravel-env-keys-checker (https://github.com/msamgan/laravel-env-keys-checker)
- tighten/duster (https://github.com/tighten/duster)
- setup prettier as per this (https://mattstauffer.com/blog/how-to-set-up-prettier-on-a-laravel-app-to-lint-tailwind-class-order-and-more)
- setup sail (https://laravel.com/docs/11.x/sail)
- Modify the composer run dev for sail (https://msamgan.com/how-to-modify-the-composer-run-dev-for-laravel-sail)
Configurations
- Add the following line of code to the AppServiceProvider
to avoid the
n+1 query
problem. To read more about the n+1 query problem, click her
/**
* Bootstrap any application services.
*/
public function boot(): void
{
$this->configureModels();
}
/**
* Configure the models.
*/
private function configureModels(): void
{
Model::shouldBeStrict(! $this->app->isProduction());
}
Make the response return a JSON response in the API routes
. (this only works in laravel 11 and above)
// bootstrap/app.php
return Application::configure(basePath: dirname(__DIR__))
//...
->withExceptions(function (Exceptions $exceptions) {
$exceptions->shouldRenderJsonWhen(function (Request $request, Throwable $e) {
if ($request->is('api/*')) {
return true;
}
return $request->expectsJson();
});
})->create();
tlint.json
Create tlint.json
at the root of your project and add the following.
{
"disabled": ["QualifiedNamesOnlyForClassName", "RemoveLeadingSlashNamespaces"]
}
pint.json
Create pint.json
at the root of your project and add the following.
{
"preset": "laravel",
"rules": {
"concat_space": {
"spacing": "one"
},
"ordered_imports": {
"sort_algorithm": "alpha"
}
}
}
Package.json
add the following in the script section
...
"lint": "npx prettier --write resources/ && ./vendor/bin/duster fix"
}
Please let me know about your initial configurations too...