CRUD Operation in Laravel 9 using resource controller
In this article, I am going to create a Laravel CRUD operation using a resource controller step by step.
In this article, we will learn How to perform CRUD operation in Laravel 9 or Laravel 8 with an example.
If you have basic knowledge of PHP, you have learned about "CRUD", CRUD refers to four basic functions of determining storage: Create, Read, Update, and Delete. It is the operations performed in the database.
Resource Controller:
Simply Laravel resource controllers provide the CRUD routes to the controller in a single line of code. or we can say single resource route in web.php

CRUD operations Laravel is a simple and basic task to perform even for beginners.
Laravel CRUD operation can be easily performed with the help of the following steps:
- Step 01: Create laravel projects and setup the database in .env file
- Step 02: Create Migration
- Step 03: Create a resource controller
- Step 04: Create resource route
- Step 05: create an index method in our controller
- Step 06: create index.blade.php
- Step 07: create create method in our controller
- Step 08: create edit method in our controller
- Step 09: create edit.blade.php
- Step 10: create update method in our controller
- Step 11: create update delete method in our controller
Step 01: Create Laravel projects and set up the database in .env file
First you have to craete a laravel projects using below command
composer create-project laravel/laravel example-app
Now you can run your projects using below command
php artisan serve
Open your browser and type url http://127.0.0.1:8000/ If every thing will be fine, you will see the welcome page
And now you have to set up your env file like below
Step 02: Create migration and run it
Now we will create a model file using the command and will pass the migration flag (-m) too, at a time it will create two files one is inside the project folder -> database->migrations and another will be inside the project folder -> app -> Models
Command for creating migration and modal at a time
php artisan make:model Post -m
Now we will create schema in the migration file for creating the posts table, Just copy and paste the below code in the migration file.
Step 03: Create a resource controller
Now we will create a PostController and will pass a --resource flag for creating a resource controller. run the below command for creating a resource controller:
php artisan make:controller PostControler --resource
Resource Controller: is nothing but it provides crud related to all methods by default and we can create all routes by writing a single line of codes which is Route::resource();
Now open the PostController.php file and call the Post model and write all needed functions one by one or just copy and paste the below code
Step 04: Create a resource route
As above describe a route provide a single URL but a resource route provides all crud-related routes.
we can create a resource route like Route::resource();
Now open web.php and copy and paste the below code.
Step 05: create all view blade file one by one
now we will create all view-related blade files inside the project folder -> resources -> views -> post
we are using bootstrap CDN for better looks.
index.blade.php
Now open your browser and type URL http://127.0.0.1:8000/post if everything is fine, you will see the below screen.
Now we will create.blade.php file inside views -> post folder
Now open your browser and type URL http://127.0.0.1:8000/post/create or click on create new post button you will see the below screen.
Now we will add some test posts so that we will test them by editing and deleting them.
I hope it is working fine.
Now we will create an edit.blade.php file inside views -> post folder
Now open your browser and type URL http://127.0.0.1:8000/post/1/edit or click on the edit button you will see the below screen.
and we have already created all methods above in our controller so that the delete button will work fine.
Hope you have created your crud operation in laravel using the resource controller and Resource route.
Note: If is there anything left or you have any error you can comment below I will reply your comment as soon as possible.