Installation
composer require blast-project/bundle-skeleton
Note: This package is deprecated, so verify compatibility with your Laravel version (likely 5.x).
Bundle Initialization
BundleServiceProvider in vendor/blast-project/bundle-skeleton/src/.config/app.php under providers:
'providers' => [
// ...
BlastProject\BundleSkeleton\BundleServiceProvider::class,
],
First Use Case: Creating a Basic Bundle
src/ directory structure to your project (e.g., app/Bundles/MyBundle/).BlastProject\BundleSkeleton) with your bundle’s namespace.php artisan vendor:publish --provider="BlastProject\BundleSkeleton\BundleServiceProvider" --tag="config"
Namespace Isolation
BundleServiceProvider as a template to enforce PSR-4 autoloading for your bundle:
// app/Bundles/MyBundle/MyBundleServiceProvider.php
namespace App\Bundles\MyBundle;
class MyBundleServiceProvider extends \BlastProject\BundleSkeleton\BundleServiceProvider {
protected $namespace = 'App\Bundles\MyBundle';
}
Service Registration
register() method to bind facades, services, or macros:
public function register() {
$this->app->singleton('my-bundle.service', function ($app) {
return new MyService();
});
}
Configuration Management
php artisan vendor:publish --provider="App\Bundles\MyBundle\MyBundleServiceProvider" --tag="config"
config() method to load defaults:
protected function config() {
$this->publishes([
__DIR__.'/config/my-bundle.php' => config_path('my-bundle.php'),
], 'config');
}
Asset Handling
publishes method:
public function boot() {
$this->loadViewsFrom(__DIR__.'/views', 'my-bundle');
$this->publishes([
__DIR__.'/public' => public_path('vendor/my-bundle'),
], 'public');
}
Command Integration
Illuminate\Console\Command in your bundle’s Console directory.boot():
public function boot() {
event(new MyBundleEvent());
}
RouteServiceProvider or directly in boot():
$this->app['router']->aliasMiddleware('my-bundle', \App\Bundles\MyBundle\Http\Middleware\MyMiddleware::class);
Deprecation Warning
RouteServiceProvider changes in Laravel 5.3+).Namespace Collisions
BlastProject\BundleSkeleton as a root namespace. Ensure your bundle’s namespace doesn’t conflict with existing code.Acme\Bundles\MyBundle).Missing Documentation
changelog or detailed README may obscure advanced features.src/ directory for undocumented patterns (e.g., BundleServiceProvider methods).Asset Publishing Quirks
public/ directory in the bundle root. Customize paths in boot() if your structure differs.$this->publishes([
__DIR__.'/resources/assets' => public_path('bundles/my-bundle'),
], 'public');
Service Provider Boot Order
ServiceProvider is registered after dependencies in config/app.php.Service Binding Issues
register() are correct:
php artisan config:clear
php artisan cache:clear
dd($this->app->bound('my-service')); // Should return true
Configuration Overrides
dd(config('my-bundle'));
Route/Asset Paths
asset() helper with explicit paths:
<link href="{{ asset('vendor/my-bundle/css/style.css') }}" rel="stylesheet">
Custom Facades
// app/Bundles/MyBundle/Facades/MyFacade.php
namespace App\Bundles\MyBundle\Facades;
use Illuminate\Support\Facades\Facade;
class MyFacade extends Facade {
protected static function getFacadeAccessor() { return 'my-bundle.service'; }
}
register():
$this->app->bind('my-facade', function () {
return new MyFacade();
});
Dynamic Configuration
boot():
$this->mergeConfigFrom(__DIR__.'/config/my-bundle-'.config('app.env').'.php', 'my-bundle');
Testing Hooks
Illuminate\Foundation\Testing\Concerns\InteractsWithServiceProviders:
use App\Bundles\MyBundle\MyBundleServiceProvider;
class MyBundleTestCase extends TestCase {
public function setUp(): void {
parent::setUp();
$this->withServiceProviders([MyBundleServiceProvider::class]);
}
}
How can I help you explore Laravel packages today?