Laravel php artisan make:model with migration and controller

Laravel php artisan make:model with migration and controller

Laravel 10, 9, and 8 create controller, model and migration using php artisan make:model and php artisan make:controller commands on command line.

This tutorial will show you how to create a simple controller using an artisan command with cmd, how to create a resource controller and api resource controller using the command with cmd, and how to model and migration using the command with cmd.

How to Create php Controller, Model and Migration in Laravel using command line

Use the following ways to create model controller and migration in one command in laravel apps:

  • 1 – Create model command
  • 2 – Create Controller command
  • 3 – Create a Resource Controller Command
  • 4 – Laravel make:model with migration and controller
  • 5 – Create Model and Migration
  • 6 – Create API Controller using Artisan
  • 7 – Laravel create model and controller in one command

1 – Create model command

You can use the php artisan make model for creating a model using the command line (CLI) :

 php artisan make:model Product

This command is to create the Product model, which is a placed on the app/models directory.

2 – Create Controller command

You can use the php artisan make:controller command for creating a controller using this command line:

 php artisan make:controller ProductController

This command will create controller named ProductController, Which is placed on app/http/controllers directory.

3 – Create a Resource Controller Command

To create the resource controller in laravel 8, so, you can execute the following command on command prompt:

php artisan make:controller ProductController --resource

PHP artisan make controller resource command creates a resource controller. It has already created some methods like index, update, edit, destroy, etc.

4 – Laravel make:model with migration and controller

If you want to create controller and model, so you can execute php artisan make:model -mc for creating a controller and model in command prompt:

 php artisan make:model Product -mcr

This single command has been created as a Product controller and model.

5 – Create Model and Migration

Execute the following command on command prompt to create model and migration file:

php artisan make:model Product -m

This single command has been created as a product controller and model.

6 – Create API Controller using Artisan

Use the following command to create api controller in laravel 8, so open command prompt and execute the following command:

php artisan make:controller API\ProductController

This command will create api product controller, which is placed on app/http/controllers/API directory.

7 – Laravel create model and controller in one command

execute the following command on command prompt to create model and migration file:

php artisan make:model Product -c

This single command has been created as a product controller and model.

Conclusion

In this tutorial, you have successfully learned how to create a controller and model. Also, learn how to create a model and resource controller using one command.

Recommended Laravel Posts

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *