Tag

Laravel CRUD

Browsing

Laravel 5.6 CRUD tutorial In this tutorial We will cover Laravel Listing, create, update, delete the basic application functionality. All Laravel application must have Larave CRUD tutorial functionality.  I will teach you how to create Laravel CRUD step by step. This tutorial is useful for Laravel beginner. Because In this tutorial I will cover all basic concept of Laravel for starting an application.

There are many Laravel CRUD generator tutorial but it is not meaning for the beginners. So, For the Beginners user, I am creating this Laravel CRUD Tutorial.

Today, We are going to learn Laravel 5.6 CRUD tutorial step by step. First of all, We are starting from going to install Laravel application.

Laravel 5.6 CRUD tutorial

We will follow the steps of the creating the Laravel 5.6 CRUD tutorial

  1. Laravel installation
  2. Database configuration
  3. Integrate AdminLte theme
  4. Write the Routes
  5. Generate migration files
  6. Create the Model
  7. Generate Controller
  8. Create the Views files

Finally, We are ready with the steps we will follow these steps for creating CRUD Tutorial.

We are going to create the category module for CRUD tutorial. Let’s start the CRUD tutorial

1 ) Laravel installation

First of all, We are going to install Laravel using composer by following the command

Follow this tutorial for installing Laravel and getting more detail about Laravel Installation.

Finally, We are ready with the Laravel Application. Now, We are going to configure Database.

2 ) Database configuration

After, Creating the  Laravel project open the configuration file “.env” then change the database configuration like

Next, We are going to run migration for generating Laravel tables

If you getting an error by following migration command like “1071 specified key was too long” then just follow this tutorial.

Finally, We are ready with the Database configuration. Now, We are going to integrate AdminLTE theme.

3 ) Integrate AdminLte theme

Finally, We are going to integrate AdminLTE theme, But I create the different tutorial for integrating AdminLTE admin theme. Because I want to make this tutorial simple and sort. So, Please follow this tutorial for integrate AdminLTE theme.

Before, Going to the next step make sure the AdminLTE theme is install properly.

4 ) Write the Routes

Finally, We are ready with the Laravel application with admin theme. Now, First of all, We are going to create the routes for our CRUD tutorial. Let’s open the routes/web.php file.

We will create the route group for all admin module URL are located on the same prefix “admin”. Also, We have namespace “Admin”. So, our Controller files are stored in the Admin folder.

5 ) Generate migration files

Now, Let’s create the migration for the category table. We have to create the category table for storing the data in a database. We generate migration file using artisan command like

After, Follow this command the Laravel generate migration for the category table. Laravel generate migration file at database/migrations/ You will see the new migration file for a category on migrations folder. Let’s open the category migration file and change the code like

Finally, We are ready with the migration table. So, Let’s run the migration first by the following command

The migrate command will create the category table into the database. So, We are ready with the category table. Now, we are going to create the Controller.

6 ) Create the Model

Finally, We are ready with the category table. Now, let’s create the Model file for the category table by following the command.

So, Laravel generates Model file inside app folder. You will find the category model file at app/Category.php  let’s open the model file then write the code like

Finally, We are ready for the Category Model. So, We are going for creating the controller file.

 7 ) Generate Controller

We are going to creating the CategoryController file. As per describe on a route. We are using the namespace Admin on the route group. So, We have to create the Controller file inside the Admin folder like “App\Http\Controllers\Admin”. So, Let’s create the Category Controller by the following command

Finally, We are ready with the Category Controller. So, Open the controller and write the code like

Finally, We are with the Category Controller. Now, We able to perform the insert, update, delete operation using category controller.

8 ) Create the Views files

Now, We are going for creating the view files. Laravel use blade template for the view file. We can create the user interface using view file. We are going to create three view files for insert, create, update.

  1. index.blade.php
  2. create.blade.php
  3. edit.blade.php

Create all those files inside “resources\views\admin\category” folder step by step.

First of all, We are going to creating the listing. So, let’s open the “resources\views\admin\category\index.blade.php” file and write the code like

Now, we are going to create the insert category form. So, let’s open the “resources\views\admin\category\create.blade.php” file and write the code like

Now, we are going to create the update category form. So, let’s open the “resources\views\admin\category\edit.blade.php” file and write the code like

We are ready with the Laravel CRUD tutorial. Now we can run the Laravel application and check the CRUD example. Follow the command for running laravel application.

Now, check the category module using this URL.

The output something look like

Laravel Crud

I hope this Laravel 5.6 CRUD tutorial is helpful for you. We are creating the reusable Laravel CRUD Code. you can reuse the module by just changing some labels on Controller file. If you face any issue by following this tutorial please write the comment below.