Skip to content

Instantly share code, notes, and snippets.

@Cannonb4ll
Last active November 16, 2020 12:03
Show Gist options
  • Save Cannonb4ll/26cceda817291236c3d7cec756938a61 to your computer and use it in GitHub Desktop.
Save Cannonb4ll/26cceda817291236c3d7cec756938a61 to your computer and use it in GitHub Desktop.
Laravel Trait Make command
Place the TraitMakeCommand.php file inside App\Console\Commands
Place the trait.stub file inside App\Console\Commands\stubs
<?php
namespace DummyNamespace;
trait DummyClass
{
//
}
<?php
namespace App\Console\Commands;
use Illuminate\Console\GeneratorCommand;
class TraitMakeCommand extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $name = 'make:trait';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new trait';
/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Trait';
/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__ . '/stubs/trait.stub';
}
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace . '\Traits';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment