flipboxstudio / lumen-generator

A Lumen Generator You Are Missing
https://packagist.org/packages/flipbox/lumen-generator
MIT License
824 stars 126 forks source link

command make model wrong dir #96

Closed socheth closed 3 years ago

socheth commented 3 years ago

On Lumen 8, I have use command make model, but it generate file outside model directory. It should be generate file in Models directory.

stsonline commented 3 years ago

I was working on a Lumen 5.8 project and wanted to move the models for consistency with an associated Laravel project. I discovered that you can set this yourself, as follows:

In app/Providers/AppServiceProvider.php add this at the top

use App\Console\Commands\ModelMakeCommand;

and inside the class add the following in the register method:

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->extend('command.model.make', function ($command, $app) {
            return new ModelMakeCommand($app['files']);
        });
    }

In app/Console/Commands create a new class ModelMakeCommand.php with the following content:

<?php

namespace App\Console\Commands;

use Flipbox\LumenGenerator\Console\ModelMakeCommand as Command;

class ModelMakeCommand extends Command
{
    /**
     * Get the default namespace for the class.
     *
     * @param  string  $rootNamespace
     * @return string
     */
    protected function getDefaultNamespace($rootNamespace)
    {
        return "{$rootNamespace}\Models";
    }
}