Я хочу создать признак, используя команду php artisan, но понятия не имею, почему она не работает.
app / Console / Stubs / trait.stub
namespace App\Traits;
trait DummyTrait
{
}
app / Console / Commands / TraitMakeCommand. php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use function app_path;
class TraitMakeCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:trait {name : Traits name you want to use.}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new trait';
/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Trait';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
return $this->getStub();
}
/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return app_path('Console/Stubs/trait.stub');
}
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace . '\Traits';
}
}
app / Console / Kernel. php
class Kernel extends ConsoleKernel
{
...
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\TraitMakeCommand::class,
];
...
}
Выход ремесленника для: pa make:trait -h
Description:
Create a new trait
Usage:
make:trait <name>
Arguments:
name Traits name you want to use.
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug