Laravel 5.4 create model, controller and migration in single artisan command

后端 未结 14 837
一整个雨季
一整个雨季 2020-12-22 14:35

I can create a model and resource controller (binded to model) with the following command

php artisan make:controller TodoController --resource --model=Todo
         


        
相关标签:
14条回答
  • 2020-12-22 15:17

    You don't need to add --resource flag just type the following and laravel will create the whole desired resources

     php artisan make:controller TodoController --model=todo
    
    0 讨论(0)
  • 2020-12-22 15:23

    We can use php artisan make:model Todo -a to create model, migration, resource controller and factory

    0 讨论(0)
  • 2020-12-22 15:24

    You can do it if you start from the model

    php artisan make:model Todo -mcr
    

    if you run php artisan make:model --help you can see all the available options

    -m, --migration Create a new migration file for the model.
    -c, --controller Create a new controller for the model.
    -r, --resource Indicates if the generated controller should be a resource controller

    Update

    As mentioned in the comments by @arun in newer versions of laravel > 5.6 it is possible to run following command:

    php artisan make:model Todo -a
    

    -a, --all Generate a migration, factory, and resource controller for the model

    0 讨论(0)
  • 2020-12-22 15:24

    Updated

    Laravel 6 Through the model

    To Generate a migration, seeder, factory, and resource controller for the model

    php artisan make:model Todo -a
    

    Or

    php artisan make:model Todo -all
    

    Other Options

    -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 inte rmediate table model

    -r, --resource Indicates if the generated controller should be a resour ce controller

    For More Help

    php artisan make:model Todo -help
    

    Hope Newbies will get help.

    0 讨论(0)
  • 2020-12-22 15:24

    To make mode, controllers with resources, You can type CMD as follows :

     php artisan make:model Todo -mcr
    

    or you can check by typing

    php artisan help make:model
    

    where you can get all the ideas

    0 讨论(0)
  • 2020-12-22 15:26

    Laravel 5.4 You can use

     php artisan make:model --migration --controller --resource Test
    

    This will create 1) Model 2) controller with default resource function 3) Migration file

    And Got Answer

    Model created successfully.

    Created Migration: 2018_04_30_055346_create_tests_table

    Controller created successfully.

    0 讨论(0)
提交回复
热议问题