GTS Joe
GTS Joe

Reputation: 4152

Difference between a 'Controller' and a 'Resource Controller' in Laravel

In Laravel, what's the difference between a regular controller and resource controller? Please provide examples to illustrate the differences.

Upvotes: 2

Views: 2817

Answers (3)

Kwabena Twumasi
Kwabena Twumasi

Reputation: 63

The only difference is that the resource controller creates a PHP file with already defined CRUD operations while a regular controller creates an empty file.

To create a regular controller with the name UserController:

php artisan make:controller UserController

To create a resource controller:

php artisan make:controller UserController --resource

Hope it was helpful. Use this for more resources https://laravel.com/docs/9.x/controllers.

Upvotes: 2

Sajid Mehmood
Sajid Mehmood

Reputation: 65

Both are Controllers but as the name suggests resource controller is an additional resource of CRUD functions

Upvotes: -2

albus_severus
albus_severus

Reputation: 3702

There is mainly no difference..It a special type of controller. When you create a controller like this

php artisan make:controller YourNameController --resource

it auto create some function like index, create, store, show, edit, update, destroy. basically for crud. For details go to documentation https://laravel.com/docs/7.x/controllers#resource-controllers

Upvotes: 4

Related Questions