CRUD Operation In Laravel 5.8 Step By Step For Beginners
Hi friends, before getting started with the tutorial CRUD operation in laravel 5.8, I want to say that Laravel latest version has changed a little bit process of coding. Assuming that you already have installed Laravel 5.8 in your system. If not yet installed then also read, how to create laravel project from scratch for beginners.
The requirements for the CRUD operation in Laravel 5.8 are as follows-
- We need a table in the database.
- Route Configuration in web.php file.
- A controller containing all the required functions.
- A model containing all the fields of the table in the database.
- We need a folder containing the following files in the resources/views folder of the public HTML folder. I have a folder name with item
All the urls are processed through web.php file inside the routes folder.
Let’s start the operation in detail
To set up the database configuration go to .env file in your laravel project and set your database as follows
Now, create a table directly in the PHPMyAdmin of the local server. In my case (WAMP Server).
DDL information of the table
id int(10) unsigned NOT NULL AUTO_INCREMENT,
item_name varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
item_description varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
updated_at timestamp NOT NULL DEFAULT ‘0000-00-00 00:00:00’,
PRIMARY KEY (
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
Now, we will set up all the route connections for the URL’s including create, read, edit, update and delete in the web.php file inside the routes folder.
Now, open your command prompt terminal and go to your project folder inside the root directory of your local server and create the controller using the below command
php artisan make:controller ItemController
Now, after the successful creation of the controller, create a model using the below command
php artisan make:model Item
Now, we will create the blade files which are shown in the browser for the CRUD operation. Blade files are given below one by one.
view_item_details.blade.php (Here you will see all the items inserted)
add.blade.php ( Here you will insert the information)
edit.blade.php ( Here you will edit the required information)
To delete, you can check the destroy function inside the controller to know how it works.
Conclusion:- I hope this article will help you to understand the basic overview of the CRUD operation in Laravel 5.8