CRUD Operations in Laravel 7 PHP Framework

Today, We want to share with you CRUD Operations in Laravel 7 PHP Framework.In this post we will show you CRUD (Create Read Update Delete) in a Laravel 7 App, hear for Laravel 7 CRUD Tutorial Example Step By Step From Scratch we will give you demo and example for implement.In this post, we will learn about Simple Laravel 7 CRUD with Resource Controllers with an example.

CRUD Operations in Laravel 7 PHP Framework

There are the Following The simple About Step by Step CRUD Operation in Laravel7 with File Upload Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 7 Tutorial For Beginners, so the laravel resource collection is used for this example is following below.

Phase 1 : Install Laravel 7

get fresh Laravel 7 version application

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

Phase 2: Database Configuration

.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=DB your name(booster_v1)
DB_USERNAME=DB username(root)
DB_PASSWORD=DB password(root)

Phase 3: Make Migration

create migration for “websites” table

php artisan make:migration create_websites_table --create=websites

path “database/migrations”

id();
            $table->string('name');
            $table->text('detail');
            $table->timestamps();
        });
    }
  
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('websites');
    }
}

Phase 4: Add Resource Route

routes/web.php

Route::resource('websites','WebsiteController');

Phase 5: Add Controller and Model

create new controller as WebsiteController

php artisan make:controller WebsiteController --resource --model=Website

app/Http/Controllers/WebsiteController.php

paginate(5);
  
        return view('websites.index',compact('websites'))
            ->with('i', (request()->input('page', 1) - 1) * 5);
    }
   
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('websites.create');
    }
  
    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request->validate([
            'name' => 'required',
            'detail' => 'required',
        ]);
  
        Website::create($request->all());
   
        return redirect()->route('websites.index')
                        ->with('success','Website created successfully.');
    }
   
    /**
     * Display the specified resource.
     *
     * @param  \App\Website  $website
     * @return \Illuminate\Http\Response
     */
    public function display(Website $website)
    {
        return view('websites.display',compact('website'));
    }
   
    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Website  $website
     * @return \Illuminate\Http\Response
     */
    public function edit(Website $website)
    {
        return view('websites.edit',compact('website'));
    }
  
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Website  $website
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Website $website)
    {
        $request->validate([
            'name' => 'required',
            'detail' => 'required',
        ]);
  
        $website->update($request->all());
  
        return redirect()->route('websites.index')
                        ->with('success','Website updated successfully');
    }
  
    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Website  $website
     * @return \Illuminate\Http\Response
     */
    public function destroy(Website $website)
    {
        $website->delete();
  
        return redirect()->route('websites.index')
                        ->with('success','Website deleted successfully');
    }
}

app/Website.php


Phase 6: Add Blade Files

resources/views/websites/layout.blade.php




    Laravel 7 CRUD Application - Pakainfo.com
    


  
@yield('content')

resources/views/websites/index.blade.php

@extends('websites.layout')
 
@section('content')
    

Laravel 7 CRUD Example from scratch - Pakainfo.com

@if ($message = Session::get('success'))

{{ $message }}

@endif @foreach ($websites as $website) @endforeach
No Name Details Action
{{ ++$i }} {{ $website->name }} {{ $website->detail }}
Show Edit @csrf @method('DELETE')
{!! $websites->links() !!} @endsection

resources/views/websites/create.blade.php

@extends('websites.layout')
  
@section('content')

Add New Website

@if ($errors->any())
Whoops! There were some problems with your input.

    @foreach ($errors->all() as $error)
  • {{ $error }}
  • @endforeach
@endif
@csrf
Name:
Detail:
@endsection

resources/views/websites/edit.blade.php

@extends('websites.layout')
   
@section('content')
    

Edit Website

@if ($errors->any())
Whoops! There were some problems with your input.

    @foreach ($errors->all() as $error)
  • {{ $error }}
  • @endforeach
@endif
@csrf @method('PUT')
Name:
Detail:
@endsection

resources/views/websites/display.blade.php

@extends('websites.layout')
@section('content')
    

Show Website

Name: {{ $website->name }}
Details: {{ $website->detail }}
@endsection
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel crud generator.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment