algoyounes/laravel-package-skeleton
Install the Skeleton Globally Run:
composer global require algoyounes/laravel-package-skeleton
Ensure your ~/.composer/vendor/bin is in your PATH.
Generate a New Package Use the scaffold command to create a new package:
composer create-project algoyounes/laravel-package-skeleton your-package-name
cd your-package-name
Replace your-package-name with your desired package namespace (e.g., vendor/package-name).
First Use Case: Bootstrapping a Package
src/ (Core logic)config/ (Package config)database/ (Migrations, seeders)resources/ (Views, assets)tests/ (Unit/Feature tests)php artisan package:publish (if included) to publish assets/config.composer test
Modular Development
Illuminate\Support\ServiceProvider in src/YourPackageServiceProvider.php.
public function register()
{
$this->app->bind('YourPackage\Contracts\YourContract', 'YourPackage\Services\YourService');
}
php artisan package:facade to generate facades (if the skeleton includes this command).
Example:
// src/Facades/YourPackage.php
public static function yourMethod() {
return app('YourPackage')->yourMethod();
}
Configuration Management
php artisan vendor:publish --provider="YourPackage\YourPackageServiceProvider" --tag="config"
config/your-package.php:
return [
'option' => env('YOUR_PACKAGE_OPTION', 'default'),
];
Database Integration
php artisan migrate --path=vendor/your-package-name/database/migrations
php artisan package:migrate (if included) for package-specific migrations.Publishing Assets
php artisan vendor:publish --provider="YourPackage\YourPackageServiceProvider" --tag="public"
resources/views/vendor/your-package/.Testing
composer test
php artisan package:test (if available) for isolated package testing.public function __construct(private YourService $service) {}
src/Events/ and listen in src/Listeners/.
Event::dispatch(new YourPackageEvent($data));
Illuminate\Console\Command in src/Console/ and register in YourPackageServiceProvider.
$this->commands([
\YourPackage\Console\YourCommand::class,
]);
ApiResource for JSON responses (if applicable).Namespace Collisions
YourPackage\) doesn’t conflict with the host app.\YourPackage\Services\YourService) in config/publishables.Autoloading Issues
composer dump-autoload
composer.json includes:
"autoload": {
"psr-4": {
"YourPackage\\": "src/"
}
}
Service Provider Registration
config/app.php:
'providers' => [
YourPackage\YourPackageServiceProvider::class,
],
Migration Paths
database/migrations) may fail in the host app. Use:
$this->loadMigrationsFrom(__DIR__.'/../../../vendor/your-package-name/database/migrations');
Testing in Isolation
Config, Filesystem) in tests:
$this->app->instance('path', $mockPath);
\Log::debug('YourPackage event triggered', ['data' => $data]);
dd(config('your-package.option'));
php artisan your:command --verbose
Custom Commands
Add new commands in src/Console/ and register them in the service provider.
Dynamic Configuration
Use config('your-package') in your package to access published settings.
Package Discovery Extend the skeleton to support Laravel Package Auto-Discovery (if needed):
// In src/YourPackageServiceProvider.php
public function boot()
{
$this->app->booted(function () {
// Post-boot logic
});
}
Local Development Link the package locally for testing:
composer config repositories.your-package-name path ./your-package-name
composer require your-package-name/dev-main
Documentation
Use Markdown in docs/ (if included) for API/usage docs. Generate with:
php artisan package:docs
How can I help you explore Laravel packages today?