Change language

Laravel | Route :: resource versus Route :: controller

|
Route::resource:the Route::resourcemethod is a RESTful controller,which generates all the main routes required for the application, and can be easily handled using a controller class. It takes two arguments, where the first - this is the base URIof the incoming request (Uniform Resource Identifier),and the second is - class nameof the controller used to process the request. With this method we get the default route names and paths, with 7 different actions that are required for any application.Note:to get a list of created routes, we have to use the command "PHP artisan route: list" on the command line.Example :
  • routes.php
     Route::resource (’gfg’, ’GeeksforGeeksController’); 
  • Output:
Route::controller: the Route::controllermethod is a implicit controller,which also takes two arguments and is similar to the Route::resource,method, i.e. the first - this is the base URIof the incoming request (Uniform Resource Identifier) ​​ and the second is - nameof the controller class that is used to process the request. With this method, we have a little flexibility in how we define our route names. By default, route names are undefined as in the Route::resourcemethod.Note.To get a list of generated routes, you must use the PHP artisan route: list "on the command line.Example :
  • routes.php:
    Route::controller (’gfg’, ’GeeksforGeeksController’); 
  • GeeksforGeeksController.php:If no method is defined in the controller class file, we get the output as shown below:
    class GeeksforGeeksController extends Controller {// Handle request} 
  • Output:
  • GeeksforGeeksController.php:When we define the get method and post in the controller class file, we get the output as shown below.
    class GeeksforGeeksController extends Controller {public function getGeek() {// Handle get request} public function postGeek ($id) {// Handle post request}} 
  • Exit:
Before specifying any of the routes, you must create the controller class that you want to use in the route. You can do this with a simple artisan command called "PHP artisan make: controller GeeksforGeeksController",that is "PHP artisan make: controller". The Route: Controllermethod was supported prior to Laravel 5.1and is no longer supported by versions after that. So, in later versions of Laravel, we use the Route::resourcemethod.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically