Skip to content

Instantly share code, notes, and snippets.

@martinbean
Last active January 19, 2016 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinbean/4c263347e7d596cb714a to your computer and use it in GitHub Desktop.
Save martinbean/4c263347e7d596cb714a to your computer and use it in GitHub Desktop.
Laravel repository make command.
<?php
namespace DummyNamespace;
class DummyClass extends Repository
{
//
}
<?php
namespace App\Console\Commands;
use Illuminate\Console\GeneratorCommand;
class RepositoryMakeCommand extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:repository';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new repository class';
/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Repository';
/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__.'/../stubs/repository.stub';
}
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Repositories';
}
}
@martinbean
Copy link
Author

Add the command class to your app/Console/Commands directory, and the stub file to app/Console/stubs. Then add the command to your app/Console/Kernel.php file:

protected $commands = [
    \App\Console\Commands\RepositoryMakeCommand::class,
];

Usage from the command line:

$ php artisan make:repository RepositoryName

Be sure to update the root namespace (App) to your application’s if you need to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment