Skip to content

Instantly share code, notes, and snippets.

@sohag-pro
Created September 8, 2022 10:47
Show Gist options
  • Save sohag-pro/dd9719b4a179b6d573b72957a0b1126b to your computer and use it in GitHub Desktop.
Save sohag-pro/dd9719b4a179b6d573b72957a0b1126b to your computer and use it in GitHub Desktop.
Create "php artisan make:service ExampleService" command
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\GeneratorCommand;
class MakeServiceCommand extends GeneratorCommand {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:service {name : Service name you want to use.}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate a service class';
/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Class';
/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return base_path('stubs/service.stub');
}
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace . '\Services';
}
}
// file path: app/Console/Commands/MakeServiceCommand.php
<?php
namespace {{ namespace }};
class {{ class }}{
}
// file location: stubs/service.stub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment