App Service Provider Checklist
The App Service Provider is the heart of your Laravel application. It is the first thing that gets loaded when your application starts and is responsible for bootstrapping your application. This checklist will help you make sure you are getting the most out of your App Service Provider.
Register vs boot
register
is for bindings and singletonsboot
is for everything else
Models
Request IDs via context
In Laravel 11 you can now use the Context
facade designed to help capture and share information throughout requests, jobs, commands and logs. https://laravel.com/docs/11.x/context
For example, creating a AddRequestContextMiddleware
:
This will share context automatically instead of remembering to pass it to across your application:
or can be retireved manually:
Helpers
Register helpers.php
file:
Local development API token middleware
As a bonus, I also like to add a middleware that allows me to authenticate as a specific user by using the user ID as the API token. This is useful for local development when you want to test the application as a specific user without having to generate a new API token each time.
Find out how to authenticate with dev tokens.