andersao / l5-repository

Laravel 5 - Repositories to abstract the database layer
http://andersao.github.io/l5-repository
MIT License
4.19k stars 877 forks source link

How to custom generator #528

Open boyteenphonui opened 6 years ago

boyteenphonui commented 6 years ago

I have many modules Module Article, Product, I use package https://github.com/nWidart/laravel-modules

How To generate everything by command artisan. For the module Article, Product ...

Thanks !

pat-och commented 6 years ago

Did you succeed? I would also like to use both together.

All advice is welcome here.

I'll keep you posted on my progress here.

osbre commented 5 years ago

Any updates here?

joaopaulopvillela commented 3 years ago

I also use both, to be able to use I created my own command to help me, but I have to keep migrating.

So I came in issues to make this request but the project is already quite crowded, I will continue migrating in the hand kkkk Detail if there are many people with this issue, I create a pull, to be able to solve the problem


namespace Modules\Sistema\Console;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class CreateRepositoryCommand extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'module:make-repository';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Criando repository';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        if(!\Module::has($this->argument('modulo'))):
            return $this->error('O modulo solicitado não foi localizado');
        endif;

        $basePath = \Module::find($this->argument('modulo'));

        \Config::set('repository.generator.basePath', $basePath->getPath());
        \Config::set('repository.generator.rootNamespace', "Modules\\{$basePath->getName()}\\");
        \Config::set('repository.generator.stubsOverridePath', $basePath->getPath());

        Artisan::call('make:repository', [
            'name' => $this->argument('repositorio')
        ]);

    }

    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return [
            ['repositorio', InputArgument::REQUIRED, 'Qual o repositorio que será criado'],
            ['modulo', InputArgument::REQUIRED, 'Em qual modulo será instalado'],
        ];
    }

    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions()
    {
        return [];
    }
}