Tagged: editable table in Laravel mysql

PHP Laravel Inline CRUD Using jQuery and AJAX 0

PHP Laravel Inline CRUD Using jQuery and AJAX

Today, We want to share with you PHP Laravel Inline CRUD Using jQuery and AJAX.In this post we will show you Create Inline CRUD Using PHP, Laravel, jQuery and AJAX, hear for HTML5 Inline Editing with Laravel 5.7, MYSQL & jQuery Ajax we will give you demo and example for implement.In this post, we will learn about Inline Table Editing using jQuery Ajax Laravel and MySQL with an example.

PHP Laravel Inline CRUD Using jQuery and AJAX

There are the Following The simple About PHP Laravel Inline CRUD Using jQuery and AJAX Full Information With Example and source code.

As I will cover this Post with live Working example to develop jQuery AJAX Inline CRUD with PHP Laravel, so the jQuery AJAX Inline CRUD using PHP Laravel MySQL for this example is following below.

Phase 1 : Install Laravel Application

Simple HTML5 Inline Editing with Laravel 5.7, MYSQL & jQuery Ajax

Laravel 5.7 version application using bellow composer command

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

Phase 2: MySQL .env files Database Configuration

database configuration in Laravel env files

.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=MyDBNAme
DB_USERNAME=DATABASE_USERNAME
DB_PASSWORD=MY_DATABASE_PASSWORD

Phase 3: Make a productlist Table and Model

make a Laravel migration for productlist table using Laravel 5.7

Table Name : productlist

php artisan make:migration create_productlist_table

database/migrations

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTagslistTable extends Migration
{
    public function up()
    {
        Schema::create('productlist', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('productlist');
    }
}

run simple Laravel commands migration

Make a Laravel 5.7 migration and Model

php artisan migrate

php artisan make:model ProductList

app/ProductList.php

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class ProductList extends Model
{
    public $table = "productlist";
    public $fillable = ['name'];
}

Phase 4: Define Laravel Routes

routes/web.php

Route::get("multipleInptFrm","[email protected]");
Route::post("multipleInptFrm","[email protected]");

Phase 5: Create ProductController

create new controller as ProductController

php artisan make:controller ProductController

app/Http/Controllers/ProductController.php

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\ProductList;
use Validator;

class ProductController extends Controller
{
    public function moreAddData()
    {
        return view("moreAddData");
    }
    public function moreAddDataPost(Request $request)
    {
        $rules = [];
        foreach($request->input('name') as $key => $value) {
            $rules["name.{$key}"] = 'required';
        }

        $validator = Validator::make($request->all(), $rules);
        if ($validator->passes()) {

            foreach($request->input('name') as $key => $value) {
                ProductList::create(['name'=>$value]);
            }

            return response()->json(['success'=>'done']);
        }
        return response()->json(['error'=>$validator->errors()->all()]);
    }
}

Phase 6: Make a Laravel Blade File

resources/views/moreAddData.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Inline Table Editing using jQuery Ajax Laravel and MySQL - Pakainfo.com</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  

 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
    <meta name="csrf-token" content="{{ csrf_token() }}">
</head>
<body>


<div class="container">
    <h2 align="center">Laravel - HTML5 Inline Editing with Laravel 5.7, MYSQL & jQuery Ajax</h2>  
    <div class="form-group">
         <form name="product_name_add" id="product_name_add">  


            <div class="alert alert-danger message-errors-display" style="display:none">
            <ul></ul>
            </div>


            <div class="alert alert-success message-display" style="display:none">
            <ul></ul>
            </div>


            <div class="table-responsive">  
                <table class="table table-bordered" id="dynamic_field">  
                    <tr>  
                        <td><input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td>  
                        <td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>  
                    </tr>  
                </table>  
                <input type="button" name="submit" id="submit" class="btn btn-info" value="Submit" />  
            </div>


         </form>  
    </div> 
</div>


<script type="text/javascript">
    $(document).ready(function(){      
      var postURL = "<?php echo url('multipleInptFrm'); ?>";
      var i=1;  


      $('#add').click(function(){  
           i++;  
           $('#dynamic_field').append('<tr id="row'+i+'" class="dynamic-added"><td><input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');  
      });  


      $(document).on('click', '.btn_remove', function(){  
           var button_id = $(this).attr("id");   
           $('#row'+button_id+'').remove();  
      });  


      $.ajaxSetup({
          headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          }
      });


      $('#submit').click(function(){            
           $.ajax({  
                url:postURL,  
                method:"POST",  
                data:$('#product_name_add').serialize(),
                type:'json',
                success:function(data)  
                {
                    if(data.error){
                        displayMessageError(data.error);
                    }else{
                        i=1;
                        $('.dynamic-added').remove();
                        $('#product_name_add')[0].reset();
                        $(".message-display").find("ul").html('');
                        $(".message-display").css('display','block');
                        $(".message-errors-display").css('display','none');
                        $(".message-display").find("ul").append('<li>Record Inserted Successfully.</li>');
                    }
                }  
           });  
      });  


      function displayMessageError (msg) {
         $(".message-errors-display").find("ul").html('');
         $(".message-errors-display").css('display','block');
         $(".message-display").css('display','none');
         $.each( msg, function( key, value ) {
            $(".message-errors-display").find("ul").append('<li>'+value+'</li>');
         });
      }
    });  
</script>
</body>
</html>

run command

php artisan serve

// open bellow URL
http://localhost:8000/multipleInptFrm

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 Inline CRUD Using jQuery and AJAX.
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.