1. First create a command file with the make: command command command
php artisan make:command ServicesCommand
2. A servicescommand file will be generated under app\console\commands
<?php namespace App\Console\Commands; use Illuminate\Console\GeneratorCommand; // GeneratorCommand class ServicesCommand extends GeneratorCommand { /** * The name and signature of the console command. * * @var string */ protected $name = 'make:service'; /** * The console command description. * * @var string */ protected $description = 'Create a new service'; /** * The console command type. */ protected $type = 'service'; // The template that the generated file depends on can be set by yourself // I put the files here in the same level as the Stubs directory protected function getStub() { return __DIR__.'/Stubs/CreateService.stub'; } // Namespaces to be used in the template protected function getDefaultNamespace($rootNamespace) { return $rootNamespace.'\Services'; } }
3. Create stubs\createservice Stub file
<?php namespace {{ namespace }}; class {{ class }} { // You can add the required code yourself }
4. Testing
// Check if the command php artisan list
// Create Test php artisan make:service TestService
5. Other
In the lower version, the class needs to be registered in the commands attribute of commands \ kernel.
protected $commands = [ ServicesCommand::class, ];
Similar Posts:
- [Solved] C# The type or namespace name ‘DllImport’ could not be found
- [Solved] Undefined reference_G++ _GLIBCXX_USE_CXX11_ ABI compilation error: STD:: Basic_String and STD::__cxx11::basic_String cannot match
- jmxÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐÐ
- Pod lib Create ObjcName error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errn…
- [Solved] Lavarel execution: PHP artisan migrate reports an error
- Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers
- [Solved] java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”
- C# – Container, Services and unity
- C# String was not recognized as a valid DateTime [How to Solve]
- [Solved] Protobuf Error: ‘tr1/unordered_map’ file not found