You are probably wondering how Laravel made some starter kits to be easily installable using just the following commands:
composer install laravel/breeze # Quickly integrates the starter kit to the composer environment
php artisan breeze:install # Quickly integrates the starter kit to the Laravel environment
If you want to build a project with the same installation setup, you are on the right track. This documentation is all about doing exactly just that. Without further ado, let's just jump right into it!
-
Prepare the working directory
mkdir /path/to/packagenamehere cd /path/to/packagenamehere
-
Make the working directory as a composer package
composer init
Simply provide the values for some prompt:
- Package name
- Syntax:
<vendor>/<name>
- Example:
vendornamehere/packagenamehere
- See reference
- Syntax:
- Description
- Example:
This is the most minimal Laravel starter kit. Built for the sake of demo.
- See reference
- Example:
- Author
- Syntax:
<Display Name>/< <email_address> >
- Example:
Juan dela Cruz <[email protected]>
- See reference
- Syntax:
- Etc
- Package name
-
Require the following packages:
illuminate/console
illuminate/support
-
Write your install command handler
/path/to/packagenamehere/src/Console/InstallCommand.php
<?php namespace VendorNameHere\PackageNameHere\Console; use Illuminate\Console\Command; class InstallCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'packagenamehere:install'; /** * The console command description. * * @var string */ protected $description = 'Description of your command'; /** * Execute the console command. * * @return int */ public function handle() { echo "Hello world!"; return Command::SUCCESS; } }
-
Write your service provider
/path/to/packagenamehere/src/Support/PackageNameHereServiceProvider.php
<?php namespace VendorNameHere\PackageNameHere\Support; use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Support\ServiceProvider; class PackageNameHereServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register any application services. * * @return void */ public function register() { // } /** * Bootstrap any application services. * * @return void */ public function boot() { if (! $this->app->runningInConsole()) { return; } $this->commands([ \VendorNameHere\PackageNameHere\Console\InstallCommand::class, ]); } /** * Get the services provided by the provider. * * @return array */ public function provides() { return [\VendorNameHere\PackageNameHere\Console\InstallCommand::class]; } }
-
Make your service provider discoverable by specifying the
extra
option./path/to/packagenamehere/composer.json
{ ... "extra": { "laravel": { "providers": [ "VendorNameHere\\PackageNameHere\\Support\\PackageNameHereServiceProvider" ] } }, ... }