-1

I found nothing about definitions/differences between resource and plain controllers.

What is the difference between them?

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
Phree
  • 29
  • 6

3 Answers3

1

When you simply create a command with **php artisan:make controller ControllerName** it will create a file with no functions in it. And you can add your functions on your own.

But if you create controller with resource then it will simply give you with all the functions you need for CRUD operation.
And with plain controller you have to create route for each functions. But with resource controller you simply add Route::resource('/routename','ControllerName'); then it will add all the routes for your index,create,store,show,edit,update and delete function. I hope this answer is helpful for you..

Anand Mainali
  • 993
  • 1
  • 14
  • 23
0

Simply definitions of controllers type is:

Resource controller is used when you perform all CRUD operations.
Plain Controller is used for anything performed manually.

Inzamam Idrees
  • 1,955
  • 14
  • 28
0

--plain

php artisan make:controller Mycontroller --plain

This will eventually make a plain constructor since you are passing the argument --plain.

The controller that you have created can be invoked from within routes.php file using this syntax below-

Example:- Route::get('base URI','Mycontroller@method');

A basic controller code will look something like this app/Http/Controller/MyController.php:

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class MyController extends Controller
{
    //
}

Resource Controllers

The resource route of Laravel allot the classic "CRUD" routes for controllers having a single line of code. This can be created quickly using the make:controller command (Artisan command) something like this"

php artisan make:controller MyController --resource

Actions Handled by Resource Controllers:

Verb       URI                   Action          Route Name

GET        /photos               index           photos.index
GET        /photos/create        create          photos.create
POST       /photos               store           photos.store
GET        /photos/{photo}       show            photos.show
GET        /photos/{photo}/edit  edit            photos.edit
PUT/PATCH  /photos/{photo}       update          photos.update 
DELETE     /photos/{photo}       destroy         photos.destroy

More Details:- Resource Controllers

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64