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

Viewed 10449

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?

2 Answers

Run this command

php artisan make:model Banana -mcr

-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

php artisan make:model Banana -mcr
Banana created successfully.
Created Migration: 2017_06_03_150652_create_bananas_table
BananaController created successfully.

OR

php artisan make:model Banana -a

where -a = all

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
Related