laravel create model from custom stub when using php artisan

↘锁芯ラ 提交于 2019-12-07 01:32:45

问题


When I use php artisan make:model CustomNamespace\TestModel, I get a model based on default stub as this :

namespace App\Models\CustomNamespace;
use Illuminate\Database\Eloquent\Model;
class TestModel extends Model
{
    //
}

But what I want to create is a dynamic Model based on my own stub to get something like this:

namespace App\Models\CustomNamespace;

use App\Models\MyParent;
/**
 * Put a dynamic doc here
 */
class MyModel extends MyParent
{
    /*put custom methods here*/
}

I've checked Laravel docs and other tutos but nothing on this, could you help guys ?


回答1:


Create a new command, extend the Illuminate\Foundation\Console\ModelMakeCommand class and override the getStub() method:

protected function getStub()
{
    if ($this->option('pivot')) {
        return __DIR__.'/stubs/pivot.model.stub';
    }

    return storage_path('/stubs/my-own-model.stub');
}


来源:https://stackoverflow.com/questions/48384903/laravel-create-model-from-custom-stub-when-using-php-artisan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!