Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a command in Laravel that can create a migration, model and controller in 1 artisan command?

Tags:

php

laravel

The main question is in the title already.

I am using Laravel 5.4 right now, is there something like

php artisan make:model Category --migrations --controller

and can generate :

create_categories_table.php [migration]

Category.php [model]

CategoryController

like image 647
Vahn Marty Avatar asked Feb 27 '17 15:02

Vahn Marty


People also ask

Which command is used to create migrations in Laravel?

To create a new migration, you can run the make:migration Artisan command and that will bootstrap a new class on your Laravel application, in the database/migrations folder.

What is the command to make controller in Laravel?

Creating the Controller From the command line in the root directory of your Laravel project, type: php artisan make:controller sharkController --resource This will create our resource controller with all the methods we need.


1 Answers

You almost guessed the right answer. Yes, it is, you can make model + migration + controller, all in one line, using command:

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

Short version: php artisan make:model -m -c Test

Result:

Model created successfully.
Created Migration: 2017_02_27_153716_create_tests_table
Controller created successfully.

For additional syntax use -h or --help flag with command make:model, it will show all available options for this command. Also you can create not just an empty controller, but a resource controller with predefined CRUD methods. For that use additional flag -r or --resource.

like image 96
Evgeniy Maynagashev Avatar answered Oct 02 '22 22:10

Evgeniy Maynagashev