Interview frequency: …
Short answer
Use register() only to bind objects in the Container without calling other services; use boot() for logic that depends on services that have already been registered.
Explanation
Laravel first runs the registration phase, iterating over every Service Provider and calling its register() method. If you try to use an event listener or another service inside register(), it may fail because the target service has not been registered yet. After all services are registered, Laravel calls boot() on every provider, when everything is ready to use safely.
Code example
class AppServiceProvider extends ServiceProvider {
public function register(): void {
$this->app->singleton(MyService::class, fn() => new MyService());
}
public function boot(): void {
// Completely safe: call models, events, and check permissions
Gate::define('view-dashboard', fn($user) => $user->isAdmin);
}
}Common mistakes
- Registering Event Listeners or querying database models inside register().
Follow-up questions
- What is the Laravel Request Lifecycle from arrival at public/index.php to the response being sent?
- How do bind, singleton, and scoped differ in Laravel's Service Container?