Laravel 8 CRUD Tutorial

Laravel is one of the most popular PHP-based framework for creating database-driven apps.

Patrick Wan

--

Laravel is described by its creators as the framework for web artisans. It’s based on the MVC (Model-View-Controller) pattern and can be used for easily creating apps for making CRUD (Create, Retrieve, Update, Delete) operations against a database.

Laravel 8 Prerequisites

In order to follow this tutorial, you’ll need to have the following prerequisites:

  • PHP and MySQL installed on your development machine,
  • Composer

Step

  • Step 1 — Install Laravel
  • Step 2 — Setting up a MySQL Database
  • Step 3 — Create a Database Migration
  • Step 4 — Add a Resource Route
  • Step 5 — Add a Controller and Model
  • Step 6 — Add Blade View
  • Step 7 — Run Development Server
  • Step 8 — Test This App

Step 1 — Installing Laravel

Let’s get started by installing Laravel 8 using Composer.

Open a new command-line interface and run the following command:

$ composer create-project laravel/laravel=8.0 testapp --prefer-dist

Step 2 — Setting up a MySQL Database

Let’s now create a MySQL database that we’ll use to persist data in our Laravel application. In your terminal, run the following command to run the mysql client:

mysql -u root -p

When prompted, enter the password for your MySQL server when you’ve installed it.

Next, run the following SQL statement to create a db database:

mysql> create database testapp;

Open the .env file and update the credentials to access your MySQL database:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db
DB_USERNAME=root
DB_PASSWORD=******

You need to provide the database name, the username and password.

--

--

Patrick Wan

My name’s Patrick. I’m a Software Developer, experience in Laravel, Vue Js, React Js, Livewire, Jquery, Codegniter, NPM, GIT. I have 5 years plus experience.