illuminate/contracts
Laravel’s core contract interfaces for frameworks and packages. Provides stable abstractions for services like cache, queue, events, routing, validation, and more, enabling clean dependency injection and easy swapping of implementations across the ecosystem.
Start by understanding that illuminate/contracts is a subtree split of interfaces from laravel/framework — it provides no implementations. In practice, developers use these interfaces in Laravel applications to decouple code from concrete services. The first step is identifying which core contracts are relevant to your use case:
Illuminate\Contracts\Mail\Mailer for sending emailsIlluminate\Contracts\Queue\Job or Queue for queueingIlluminate\Contracts\Cache\Repository for cachingIlluminate\Contracts\Http\Kernel for HTTP request lifecycleIn a Laravel app (which already depends on laravel/framework), these interfaces are automatically registered — you can immediately type-hint them in constructors or service method signatures. Start using them by modifying a service (e.g., a job or middleware) to depend on Cache\Repository instead of CacheManager or a facade.
Bind custom implementations in service providers:
// AppServiceProvider@boot
$this->app->bind(\Illuminate\Contracts\Mail\Mailer::class, \App\Mail\CustomMailer::class);
Then inject \Illuminate\Contracts\Mail\Mailer in services — Laravel resolves CustomMailer.
Implement contract interfaces for extensibility:
Build a class like class MyQueueJob implements Job to integrate with Laravel’s queue worker. Ensure method signatures match the contract exactly (e.g., fire(), failed()).
Test in isolation:
Use mock(\Illuminate\Contracts\Redis\Factory::class) in unit tests to stub Redis without bootstrapping the full app — avoids overhead and external dependencies.
Package development:
Require "illuminate/contracts": "^11.0" in your package, type-hint against contracts (e.g., Http\Kernel), and document how consumers should bind their own implementations — making your package framework-agnostic by interface.
illuminate/contracts standalone: It lacks implementations and will cause fatal errors. Only install it via laravel/framework. If you see it in composer.lock, it’s there as a transitive dependency — do not pin it directly.Cache\Repository contract may lack methods added in Laravel 11. Always align illuminate/contracts with your Laravel major version (check laravel/framework’s composer.json for the exact constraint).php artisan about to verify installed Laravel version and confirm contract compatibility.Cache\Repository), define App\Contracts\Cache\ExtendedRepository to avoid tightly coupling to Laravel internals and reduce breakage on upgrades.php artisan route:clear && php artisan config:clear && php artisan cache:clear
Then inspect binding resolution in Tinker:
>>> app(\Illuminate\Contracts\Auth\Factory::class)
How can I help you explore Laravel packages today?