Laravel 7 CRUD ( Create , Read, Update, Delete) Example Tutorial

Hey Artisan

In this tutorial i am going to discuss about laravel crud example. In this tutorial i will create a simple crud app in laravel 7 from step by step. If you are new to laravel then you are a right place. i will discuss laravel 7 crud from scratch.

So from this  Laravel 7 CRUD operations tutorial you will learn how to fetch data using get request, how delete data using delete request, how to edit or update data using put or patch request and how to save or insert data using post request.

In this laravel 7 crud example i will create a customer model and i will generate crud using this customer model. In this laravel crud tutorial i also use route model binding to see single data or update to hiding the id of customer and i will use customer slug rather id to show single data.

I will also validate the form before submit and i will show error message of form request data. It is going to be a very simple crud operation of Laravel 7 application for beginners. CRUD is a commonn operation of every application. So let's learn laravel crud operation from scratch.

Table of Contents

  • Download Laravel 7
  • Connect Database
  • Make Model and Migration
  • Make Routes
  • Make Controller
  • Make Blade File
  • Conclusion


Recommended : Laravel 7.x Rest API CRUD Example with JWT Auth


Preview: Insert form of laravel crud operation



Preview: Edit form of laravel crud operation



Preview: View single data of laravel crud operation



Preview: Confirmation before delete data of laravel crud tutorial



Preview: List of customer of laravel crud tutorial



Step 1 : Download Laravel

After installing composer in your environment just run below command to download fresh laravel app. As we are going to start laravel crud from step by step. So download it via command.

composer create-project --prefer-dist laravel/laravel blog


Step 2: Connect Database 

In this we need to connect database. Cause without database we can't insert update view or delete our data. So connect it like below.




Step 3: Create Model and Migration

Now in this step we need to create our model and migration to get table to create laravel 7 crud application. run below command to create model and migration file.

php artisan make:model Customer -m


Recommended : Laravel 7.x Ajax CRUD Example with Sweet Alert



    public function up()
        Schema::create('customers', function (Blueprint $table) {


Now run this below command to migrate this table.

php artisan migrate


Now open contact model and paste this below code.


namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
   // protected $guarded = []; or you can use
	protected $fillable = [

	public function getRouteKeyName()
		return 'slug';


Step 4: Create Routes

Now time to create our routes to make laravel crud applications. Now open "routes/web.php"  and paste below code.


Route::get('/customer', 'TestController@add_customer_form')->name('customer.add');
Route::post('/customer', 'TestController@submit_customer_data')->name('');
Route::get('/customer/list', 'TestController@fetch_all_customer')->name('customer.list');
Route::get('/customer/edit/{customer}', 'TestController@edit_customer_form')->name('customer.edit');
Route::patch('/customer/edit/{customer}', 'TestController@edit_customer_form_submit')->name('customer.update');
Route::get('/customer/{customer}', 'TestController@view_single_customer')->name('customer.view');
Route::delete('/customer/{customer}', 'TestController@delete_customer')->name('customer.delete');


Step 5:  Create Controller

In this step we need to create our TestController to create all the method to complete laravel crud operation. So run below command to create TestController

php artisan make:controller TestController


Now in this step open TestController and paste this below code in it.


namespace App\Http\Controllers;

use App\Customer;
use Illuminate\Http\Request;

class TestController extends Controller
    public function add_customer_form()
      if( \View::exists('customer.create') ){

        return view('customer.create');


    public function submit_customer_data(Request $request)
      $rules = [
          'name' => 'required|min:6',
          'email' => 'required|email|unique:customers'

      $errorMessage = [
          'required' => 'Enter your :attribute first.'

      $this->validate($request, $rules, $errorMessage);
         'name' => $request->name,
         'slug' => \Str::slug($request->name),
         'email' => strtolower($request->email)

      $this->meesage('message','Customer created successfully!');
      return redirect()->back();


    public function fetch_all_customer()
       $customers = Customer::toBase()->get();
       return view('customer.index',compact('customers'));

    public function edit_customer_form(Customer $customer)
       return view('customer.edit',compact('customer'));

    public function edit_customer_form_submit(Request $request, Customer $customer)
      $rules = [
          'name' => 'required|min:6',
          'email' => 'required|email|unique:customers'

      $errorMessage = [
          'required' => 'Enter your :attribute first.'

      $this->validate($request, $rules, $errorMessage);

                    'name' => $request->name,
                    'email' => strtolower($request->email)

      $this->meesage('message','Customer updated successfully!');
      return redirect()->back();

    public function view_single_customer(Customer $customer)
      return view('customer.view',compact('customer'));

    public function delete_customer(Customer $customer)
      $this->meesage('message','Customer deleted successfully!');
      return redirect()->back();

    public function meesage(string $name = null, string $message = null)
        return session()->flash($name,$message);



Step 6: Create Blade File


Recommended : Laravel 7.x Livewire CRUD Tutorial


We are set to and we are in the final step to complete this laravel 7 crud tutorial example. Just we need to create some blade file to see our data and form to submit data. 











Recommended : Laravel 7.x Vue js CRUD Example With Vue Router


Now our laravel 7 crud example tutorial is over. Now you can check it by visiting the following url.




Recommended : Building a REST API with Laravel Microservices Lumen


Hope it can help you and you have leart something new from this laravel crud tutorial. Now you know how to update data delete data view data and insert data in laravel.


#laravel #laravel-7 #laravel-7x #crud #form-validation #example #tutorial