Laravel comes with lots of time-saving gems out-of-the-box, resourceful routes is one of them.
In this article, we will explore the resource routes, how to define one, and what we get in return.
What is a resource route?
A resource route is a shortcut route that can be defined in a routes file. The resource style route will state that there will be data related to the route and therefore, we need the generic CRUD (create, read, update, and delete) routes. This can be also known as a RESTful route.
Once defined, there will be seven routes immediately configured within the application routing system.
How to define a resource route
Now for some magic syntax, in the applications routes file, for example, specifically in the routes/web.php file, add the following syntax.
And that is it, all seven routes are magically stacked behind this syntax. We can check this by running the following
php artisan route:list command.
This is the output of the route list –
And that is a resourceful route in a nutshell. If you’re interested in creating a CRUD style application, you can follow my tutorial on creating a CRUD app with resource controllers here.