What is a Resource Controller in Laravel, and what are its Actions?
Table of contents
As a web developer with years of experience, working with Laravel is still no joke! It is a long way of learning, but also it is fun and useful for anyone who is interested in web development. For those who don’t know what Laravel is, “it is a web application framework with expressive, elegant syntax.”
There are some things one should know about using resource controllers in Laravel. In this blog, I intend to tell you what a resource controller is and what its actions are. I hope this blog helps you with web development.
What is a Resource Controller in Laravel?
Backend developers like me construct standardized projects on a regular basis as part of our day-to-day work, particularly for CRUD operations. We give each of them their own specific tasks within our controller, and we also build routes for each, which can be a time-consuming and, at times, difficult process.
This procedure requires more of our time and effort, and consequently, it lengthens the amount of time it takes to produce any given product or complete any given job. CRUD operations are very common, and everyone here is familiar with them.
C = Create
R= Retrieve
U= Update
D= Delete
Laravel Controller provides a facility for generating a controller with all these CRUD operations prebuilt with a single line comment, and this controller is known as Resource Controller.
Here is the command for the Resource controller:
php artisan make: controller controllerName –resource
Actions of Resource Controller
A resource controller provides us with a total of seven methods with different actions
These actions are:
- index
- create
- store
- show
- edit
- update
- destroy
Initializing the resource controller in our routing file:
We can initialize the resource controller routes by using the below snippet in our web.php file, which is located in the routes folder of our Laravel project using the below snippet, i.e.,
use AppHttpControllerscontrollerName;
Route::resource(‘photos’, controllerName::class);
Let’s take a look at the seven actions that a resource controller provides to us:
1. Index Method
Route Name: controllerName.index
Request Method: GET
The pages of all the records are displayed using this method. If you have a product page, for example, you will use the index method to retrieve all of the records and show them in the view in the appropriate order.

2. Create Method
Route Name: controllerName.create
Request Method : GET
This method is used to display the form for creating the record in the table. For example, if you have a product table, we will create a form for the user to use to enter values for the products in the database, and then we will display that form to the user.

3. Store Method
Route Name: controllerName.store
Request Method: POST
This method is used to store the record in the table. For example, if you have a product table, then insert values in the products table by sending the params in a POST request in the route.

4. Edit Method
Route Name: controllerName.edit
Request Method: GET
This method is used to show the editing form for a specified resource. This function takes the id as an argument. It can be the primary key or any unique key of the table.

5. Show Method
Route Name: controllerName.show
Request Method: GET
Used to show the results for the specified resource from the database.

6. Update Method
Route Name: controllerName.update
Request Method: PUT/PATCH
Now we use that method to update the specified resource. This method takes arguments by following the PUT or PATCH as a request method followed by a unique id of the record we want to update.

7. Destroy Method
Route Name: controllerName.delete
Request Method: DELETE
Whenever we create a record, we also want a method and route for deleting this record. By using the destroy method of the resource controller, we can do the same. It takes the id of the table as an identifier for which record you want to delete.

After initializing your resource controller in the routes file, you can check your listed routes by command:
php artisan route:list
The outcome in your terminal will be:

8. Initializing the Specified Methods
When we initialize the resource controller routes, we can also define only the required routes. For example, if we need only the index and show method, then we can initialize the routes for only these two methods. If our controller name is PhotoController, then the code for doing the same is:

9. Defining API Resource Routes
We can also define the resource routes of these resource controllers for the APIs. For this, we will follow the below snippet :

So, these are the main aspects of a resource controller.
Wrapping Up
And yes, it’s it’s a wrap! I hope you understand what resource controllers are and also their actions. Using Laravel is fun when you know what you are doing. You can make the most out of it by understanding it better.
There’s a lot to learn, explore, understand and use in web development. I hope this blog added to your knowledge.
For web design and web development services, you can count on webdew! Our expert team can get you the best services possible. Visit www.webdew.com to know more! Or even better, contact us!
Editor: Amrutha
Frequently Asked Questions
What is the difference between resource and controller in Laravel?
- Resource: In the context of routes, a resource is a way to define a group of routes for a controller that handles typical CRUD (Create, Read, Update, Delete) functions on a resource, such as a database table.
- Controller: It is a PHP class responsible for handling incoming HTTP requests and controlling the application’s logic. A controller contains methods that correspond to different actions or routes, and it interacts with models and views to generate responses.
What is the resource route in Laravel?
How to use resource controller in Laravel 8?
- Create a controller: Use the php artisan make: controller command to generate a resource controller, specifying the –resource flag.
- Define routes: In your web.php or api.php file, use the Route::resource() method to define resource routes that map to the controller’s actions.
- Implement controller methods: In the generated controller, implement methods like index(), create(), store(), show(), edit(), update(), and destroy() to handle CRUD operations.
- Views: Create view files for each controller action if needed.
- Access routes: You can access the routes like /resource (index), /resource/create (create), /resource/{id} (show), etc., where “resource” is the name of the resource you defined.
What is the function of a resource controller?
Dive Into our Client Testimonials
Listen to business owners like you share how we’ve helped them grow. Your story could be next!
The webdew team is very supportive, they provide us with thoughtful suggestions.
We contracted webdew to build our new website. And let me tell you, they did a fantastic job. Their team was really easy to communicate with.”
The webdew team is very supportive, they provide us with thoughtful suggestions.
We contracted webdew to build our new website. And let me tell you, they did a fantastic job. Their team was really easy to communicate with.”
The webdew team is very supportive, they provide us with thoughtful suggestions.
We contracted webdew to build our new website. And let me tell you, they did a fantastic job. Their team was really easy to communicate with.”
“We worked with Chehak over the past several months to create a series of animated videos for an academic planner that we produce. And from the very beginning, she was absolutely professional and a pleasure to work with.”
6x
We helped clients multiply their website conversion rates through strategic design and UX optimization.
20%
Our marketing campaigns led to a 20% uplift in customer engagement across digital channels.
2K+
Delivered over 2,000 qualified leads through targeted funnels and smart automation.
120+
Our video content has earned 120,000+ views, driving brand awareness and audience retention.
“I recently had the pleasure of working with Chehak on a video demo project, and I was thoroughly impressed with her services.”
Additional Resources
Access expert tips, trends, and strategies designed for small businesses. Stay ahead of the curve and make informed decisions with our comprehensive resources!