Install via Composer:
composer require vendor/package-name
Publish the package's configuration (if applicable) with:
php artisan vendor:publish --provider="Vendor\PackageName\PackageServiceProvider"
For Laravel 11/12, ensure your config/app.php includes the service provider in the providers array under the correct framework version section. The package now officially supports both Laravel 11.x and 12.x, so no additional setup is required beyond standard Laravel initialization.
First use case: Use the package's facade or helper directly in a controller or command:
use Vendor\PackageName\Facades\PackageFacade;
Route::get('/example', function () {
return PackageFacade::doSomething();
});
Service Integration:
AppServiceProvider (if not auto-discovered):
public function register()
{
$this->app->singleton('package.service', function ($app) {
return new \Vendor\PackageName\Services\PackageService();
});
}
bind() method in AppServiceProvider if using dependency injection:
public function register()
{
$this->app->bind(\Vendor\PackageName\Contracts\PackageContract::class, function () {
return new \Vendor\PackageName\Services\PackageService();
});
}
Configuration:
config('package.key'). Example:
$timeout = config('package.timeout', 30); // Fallback to 30 if undefined
config/package.php (published via vendor:publish).Event Listeners:
EventServiceProvider (Laravel 11/12 compatible):
protected $listen = [
\Vendor\PackageName\Events\PackageEvent::class => [
\App\Listeners\HandlePackageEvent::class,
],
];
Middleware:
app/Http/Kernel.php under $middleware or $routeMiddleware:
protected $routeMiddleware = [
'package.middleware' => \Vendor\PackageName\Http\Middleware\PackageMiddleware::class,
];
Model Casting (Laravel 11+): If the package includes model traits or casts, use them in your Eloquent models:
use Vendor\PackageName\Casts\PackageCast;
class MyModel extends Model
{
protected $casts = [
'attribute' => PackageCast::class,
];
}
Route Model Binding (Laravel 12): For custom route binding logic, extend the package's resolver:
Route::bind('package', function ($value, $route) {
return \Vendor\PackageName\Services\PackageService::resolve($value);
});
Service Provider Auto-Discovery:
config/app.php under providers. Ensure the package's provider is listed:
'providers' => [
// Laravel Framework Service Providers...
Vendor\PackageName\PackageServiceProvider::class,
],
PackageManifest, verify the package is listed in bootstrap/app.php:
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/routes/web.php',
commands: __DIR__.'/routes/console.php',
api: __DIR__.'/routes/api.php',
channels: __DIR__.'/routes/channels.php',
)
->withMiddleware(function ($middleware) {
$middleware->alias('package.middleware', \Vendor\PackageName\Http\Middleware\PackageMiddleware::class);
})
->create();
Facades and Aliases:
Illuminate\Support\Facades\Facade class. If the package uses a facade, ensure its alias is defined in config/app.php:
'aliases' => [
'Package' => Vendor\PackageName\Facades\PackageFacade::class,
],
Blade Directives:
AppServiceProvider:
public function boot()
{
\Vendor\PackageName\Blade::register();
}
Configuration Caching:
php artisan config:clear
php artisan optimize:clear
Dependency Injection:
public function __construct(private PackageContract $package) {}
Queue Workers:
php artisan queue:work
.env:
QUEUE_CONNECTION=database
Testing:
$this->mock(Vendor\PackageName\Contracts\PackageContract::class, function ($mock) {
$mock->shouldReceive('doSomething')->andReturn('mocked');
});
Customizing Behavior:
AppServiceProvider:
$this->app->bind(
Vendor\PackageName\Contracts\PackageContract::class,
App\Services\CustomPackageService::class
);
Adding Commands:
AppServiceProvider:
$this->commands([
\App\Console\Commands\CustomPackageCommand::class,
]);
Event Customization:
Event::listen(\Vendor\PackageName\Events\PackageEvent::class, function ($event) {
// Custom logic
});
Views and Assets:
php artisan vendor:publish --tag=package-views
php artisan vendor:publish --tag=package-assets
resources/views/vendor/package/ or public/vendor/package/.How can I help you explore Laravel packages today?