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
    add.blade.php
    edit.blade.php
    view_item_details.blade.php

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

CREATE TABLE items (
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 (id)
) 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.

web.php

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

ItemController

Now, after the successful creation of the controller, create a model using the below command

php artisan make:model Item

Item.php (Model)

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

Also, Read How To Run Laravel On Localhost Without PHP Artisan Serve

--

--

--

Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to practice Python — a few useful tips

REAL TIME DISTANCE CALCULATION USING ARUCO MARKERS

Soft Hedge/Leverage Launch on Entropyfi

Why Referential Transparency matters?

Beta Sign-ups…

How to Integrate OPA With Terraform

Firebase Push Notification Tutorial

Amazon EKS Task

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bipsmedium

Bipsmedium

Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.

More from Medium

Why should we use Laravel blade ?

Laravel Blade Template

Laravel 9 Auth Login and Registration

How to upgrade Laravel 8 to Laravel 9

Laravel CRUD | Laravel 8 CRUD Application Tutorial for Beginners