CRUD App using Laravel 8 with Bootstrap 4 and MYSQL— Laravel 8 Tutorials for Beginners

Raman Singh
3 min readApr 15, 2021
Laravel 8
Laravel official Logo

Laravel is one of the most popular PHP Framework available in market and trusted by developers. Laravel 8x (latest) got many new features as compared to Laravel 7x. In this tutorial, we will learn How to Create CRUD App using latest Laravel 8x. Let’s begin.

What’s New in Laravel 8 ?

  • Laravel Jetstream
  • Job Batching
  • Improved Rate Limiting
  • Model Factory Classes
  • Models Directory
  • Dynamic Blade Components
  • Artisan Improvements

Introduction

Getting started with Laravel is easy. In this tutorial, we create simple application using Laravel to understand CRUD i.e Create, Read, Update & Delete operations in Laravel 8.

Preview CRUD APP — Customers List

Install & Configuration

Prerequisites

  • PHP >= 7.3
  • MYSQL
  • COMPOSER

Installation

Laravel can be installed using composer in command line. Run these commands to install and run default laravel.

composer create-project laravel/laravel crudappcd crudappphp artisan serve

For more details related Laravel Installation. Click Here

Configuration

Go to phpmyadmin. For localhost — http://localhost/phpmyadmin

Create Database.

Open .env file in your root folder. If you can’t see the file. make sure hidden files are visible.

DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_crud
DB_USERNAME=root
DB_PASSWORD=

Database

create migration file and paste this code.

To create migration file, open command line and go to root directory of your app and run the below command..

php artisan make:migration create_customers_table

Open ./database/migrations folder and open create_customers_table.php file

create_customers_table.php

Save and then go to terminal and run this command.

php artisan migrare

This is will create customers table in database. Now we have database ready and configured properly.

In case, you face any issue with running migration file. Here is SQL to create table.

Route

/routes/web.php

Here, resource will be automatically create routes for CRUD operations. For instance -

  • Create — /customers/create
  • List — /customers
  • Update — /customers/{id}/edit
  • View — /customers/{id}
  • Delete — /customers/{id}/delete

Controller

As, we will be performing CRUD operations. We can create a resource Controller. Resource Controllers are the controllers which provide us ready to use methods for CRUD Operations.

Open Command line and run this command.

php artisan make:controller CustomersController — resource

CustomersController.php

Model

Now we have controller. Its time to create a model.

Open Command line and run this command.

php artisan make:model Customer

/app/Models/Customer.php

Views

So now we have controller and model ready, we can move to creating views. As we know, in Laravel all views are in /resources/views folder. So open this path.

Firstly, we need to create layout. Create file layout.blade.php

/resources/views/layout.blade.php

Create the folder customers and create the below files and copy the code respectively.

/resources/views/customers/index.blade.php — list all customers

/resources/views/customers/create.blade.php — create form to add new customer

/resources/views/customers/edit.blade.php — edit customer with customer id

/resources/views/customers/show.blade.php — view customer by id

Conclusion

Congratulations, we have successfully built our first CRUD APP using Laravel 8 and MYSQL. Now, you can start exploring the code to understand more about logic and stuff. You can easily customize and create more Sections with CRUD Operations like users, roles, books, etc.

If you face any issue, feel free to comment your doubt. You can also refer to GitHub Repo and clone it.

GitHub URL : https://github.com/raman-saluja/crudapp

--

--