Search code examples
laravelmodelcontrollermigration

Laravel: Create an API Controller, model and migration in one line


This is what I use at the moment to create Controller and Model

php artisan make:controller API/name_of_controller --api --model=name_of_model

then create a migration

php artisan make:migration create_users_table

In the past before I started using API, I used to do this to create model, migration and controller in one single line

php artisan make:model Banana -mcr

Is there a way to do this with API controller?


Solution

  • I think there is no existing command to do that. How you create them currently is the best solution

    php artisan make:controller API/TestController --api --model=Test
    # then
    php artisan make:migration create_tests_table
    

    Why?

    php artisan help make:controller
    php artisan help make:model
    
    1. Currently there is no option to include a migration file when creating a controller first
    2. And there is no option to specify a controllers name (e.g. --controller=API/TestController when using make:model command