Laravel 使用资源丰富的控制器创建模型

Laravel 使用资源丰富的控制器创建模型,laravel,rest,laravel-artisan,Laravel,Rest,Laravel Artisan,我知道我可以使用命令php-artisan-make:model-Task-c创建一个带有控制器的模型,我还可以使用php-artisan-make:controller-TasksController-r创建一个资源丰富的控制器。有没有办法用一个资源丰富的控制器创建这两个模型?您可能想看看生成器包 是的,您可以不使用软件包来完成此操作。如果运行php artisan make:model--help,您将找到可以添加到命令中的选项 php artisan make:model --hel

我知道我可以使用命令
php-artisan-make:model-Task-c
创建一个带有控制器的模型,我还可以使用
php-artisan-make:controller-TasksController-r
创建一个资源丰富的控制器。有没有办法用一个资源丰富的控制器创建这两个模型?

您可能想看看生成器包


是的,您可以不使用软件包来完成此操作。如果运行
php artisan make:model--help
,您将找到可以添加到命令中的
选项

php artisan make:model --help

Options:
-c, --controller  Create a new controller for the model.
-r, --resource    Indicated if the generated controller should be a resource controller
因此,如果同时使用
c
r
标志运行它,它将生成
模型
,以及资源
控制器

php工匠制作:模型任务-c-r

注意:这适用于
=5.3版本

示例

php artisan make:model Product -c

  -a, --all             Generate a migration, seeder, factory, and resource controller for the model
  -c, --controller      Create a new controller for the model
  -f, --factory         Create a new factory for the model
      --force           Create the class even if the model already exists
  -m, --migration       Create a new migration file for the model
  -s, --seed            Create a new seeder file for the model
  -p, --pivot           Indicates if the generated model should be a custom intermediate table model
  -r, --resource        Indicates if the generated controller should be a resource controller
      --api             Indicates if the generated controller should be an API controller
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

我建议一个简单的方法,在laravel 7中100%适用于我

php artisan make:model ModelName -mr
此命令将使用resourceful controller以及迁移创建一个新模型

-m
表示用于迁移
-r
创建资源丰富的控制器并将其与模型关联


希望这对您有用

谢谢您的回答,通常我会执行
php artisan make:model Task-mc
但是当我尝试运行
php artisan make:model Task-mcr时,它给了我一个错误,我想我从来没有想过逐个传递选项,这对前面的回答没有任何影响。很抱歉