Created
September 8, 2022 10:47
-
-
Save sohag-pro/dd9719b4a179b6d573b72957a0b1126b to your computer and use it in GitHub Desktop.
Create "php artisan make:service ExampleService" command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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