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.


Best laptop for Sims 4


Best laptop for Zoom


Best laptop for Minecraft


Best laptop for engineering student


Best laptop for development


Best laptop for Cricut Maker


Best laptop for hacking


Best laptop for Machine Learning


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers


Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method