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

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...