Posted inTechnology / Laravel / Mysql / php / Programming

PHP Laravel 5.7 insert update delete in MySQL Example

Today, We want to share with you PHP Laravel 5.7 insert update delete in MySQL Example.In this post we will show you insert update delete in php Laravel 5.7, hear for Laravel 5.7 insert update delete in php with source code
we will give you demo and example for implement.In this post, we will learn about how to insert update delete record using php Laravel 5.7 and mysql with an
example.

PHP Laravel 5.7 insert update delete in MySQL Example

There are the Following The simple About PHP Laravel 5.7 insert update delete in MySQL Example Full Information With Example and source
code.

As I will cover this Post with live Working example to develop insert update delete in php Laravel 5.7 with source code download, so the some major files and
Directory structures for this example is following below.

Step 1 : Install Laravel 5.7

Run bellow command Laravel 5.7

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

Step 2: Settings Database Configuration

Laravel 5.7 .env files

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=atmiya25
DB_USERNAME=root
DB_PASSWORD=

Step 3: Create Laravel 5.7 Table

Laravel 5.7 php artisan command,

php artisan make:migration create_categorys_table --create=categorys

“database/migrations”

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

Run this command to create MySQL table

php artisan migrate

Step 4: Create Resource Route

routes/web.php

Route::resource('categorys','categoryController');

Step 5: Make Laravel 5.7 Controller and Model

Create Laravel 5.7 Controller

php artisan make:controller categoryController --resource --model=category

Laravel 5.7 Controllers

app/Http/Controllers/categoryController.php

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

Laravel 5.7 Model

app/category.php


  • layout.blade.php
  • index.blade.php
  • create.blade.php
  • edit.blade.php
  • show.blade.php

Step 6: Create Laravel 5.7 Blade Files

resources/views/categorys/layout.blade.php




    Laravel 5.7 CRUD Application - pakainfo.com
    


  
@yield('content')

resources/views/categorys/index.blade.php

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

Laravel 5.7 CRUD Example from scratch - pakainfo.com

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

{{ $message }}

@endif @foreach ($categorys as $category) @endforeach
No categorys Name informations Action
{{ ++$i }} {{ $category->name }} {{ $category->information }}
Show Edit @csrf @method('DELETE')
{!! $categorys->links() !!} @endsection

resources/views/categorys/create.blade.php

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

Add New category

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

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

resources/views/categorys/edit.blade.php

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

Edit category

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

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

resources/views/categorys/show.blade.php

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

Show category

Name: {{ $category->name }}
informations: {{ $category->information }}
@endsection

Laravel 5.7 Save and quick run

php artisan serve

Run Laravel 5.7 project

http://localhost:8000/categorys
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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

I hope you get an idea about PHP Laravel 5.7 insert update delete in MySQL Example.
I would like to have feedback on my Pakainfo.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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype