Today, We want to share with you jQuery AJAX Inline CRUD using Laravel MySQL.In this post we will show you jQuery AJAX Inline CRUD using Laravel, hear for Inline Editing using Laravel MySQL and jQuery Ajax we will give you demo and example for implement.In this post, we will learn about Simple Laravel Jquery Ajax CRUD(insert update delete) tutorial example with source code with an example.
jQuery AJAX Inline CRUD using Laravel MySQL
There are the Following The simple About jQuery AJAX Inline CRUD using Laravel MySQL Full Information With Example and source code.
As I will cover this Post with live Working example to develop Laravel MySQL Inline Editing using jQuery Ajax, so the some Live Add Edit Delete Datatables Records using Laravel Ajax for this example is following below.
Step : 1 Laravel Routes
Define a Laravel routes:
Route::get('Product', ['uses' => 'ProductController@index']); Route::post('Product/update/{id}', ['as' => 'Product/update', 'uses' => 'ProductController@update']); Route::post('Product/multiple_update', ['as' => 'Product/multiple_update', 'uses' => 'ProductController@multiple_update']);
Step : 2 Laravel Migration
Make A Simple Laravel migration.
increments('id'); $table->timestamps(); $table->string('name')->nullable(); $table->float('value')->nullable(); $table->date('date')->nullable(); }); } public function down() { Schema::drop('products'); } }
Laravel Run migration using below command:
php artisan migrate
Add some data to Database.
Step : 3 Laravel Model
Make a Laravel model Product.php
Step : 4 Laravel controller
4. Make a Laravel controller (ProductCpntroller):
orderBy('id') ->get() ; // $Product_columns = Schema::getColumnListing('products'); $Product_model = new Product(); $fillable_columns = $Product_model->getFillable(); foreach ($fillable_columns as $key => $value) { $Product_columns[$value] = $value; } return view('Product.index') ->with('Product', $Product) ->with('Product_columns', $Product_columns) ; } public function update(Request $request, $id) { $Product = Product::find($id); $column_name = Input::get('name'); $column_value = Input::get('value'); if( Input::has('name') && Input::has('value')) { $Product = Product::select() ->where('id', '=', $id) ->update([$column_name => $column_value]); return response()->json([ 'code'=>200], 200); } return response()->json([ 'error'=> 400, 'message'=> 'Sorry, Not enought params' ], 400); } public function multiple_update(Request $request) { if (Input::has('products_id_edit') && Input::has('bulk_name') && Input::has('multiple_data_val')) { $ids = Input::get('products_id_edit'); $bulk_name = Input::get('bulk_name'); $multiple_data_val = Input::get('multiple_data_val'); foreach ($ids as $id) { $Product = Product::select() ->where('id', '=', $id) ->update([$bulk_name => $multiple_data_val]); } $message = "Done"; } else { $message = "Error. Empty or Wrong data provided."; return Redirect::back()->withErrors(array('message' => $message))->withInput(); } return Redirect::back()->with('message', $message); } }Step : 5 Laravel View File
Make a Laravel view file in resources/views/Product/index.blade.php
@extends('app') @section('content')@endsection @section('scripts') @endsection@if (count($errors) > 0)Sorry! We have some erros@endif @if(Session::has('message'))@foreach ($errors->all() as $error)
- {{ $error }}
@endforeach{!!Session::get('message')!!}@endifMultiple edit
{!! Form::open(['action' => 'ProductController@multiple_update', 'method' => "POST", "class"=>"form-inline"]) !!}{!! Form::select('bulk_name', $Product_columns, [], ['class' => 'form-control']) !!}{!! Form::text('multiple_data_val', null, ['class' => 'form-control'])!!}
@foreach($Product as $t)
{!! Form::close() !!}@endforeach {{$t->id}} {{$t->name}} {{$t->value}} {{$t->date}} Step : 6 Laravel Main Layout
6. Make Main Application Layout view file in
resources/views/app.blade.php
Inline Editing using PHP Laravel MySQL and jQuery Ajax @yield('content') @yield('scripts')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 jQuery AJAX Inline CRUD using Laravel MySQL.
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.