Today, We want to share with you Create Laravel Live Search Using Ajax.In this post we will show you Create Live Search Box In Laravel 5.8, hear for Ajax Live Search Table Generation in Laravel we will give you demo and example for implement.In this post, we will learn about Build a live search feature with Laravel and Vue.js with an example.
Create Laravel Live Search Using Ajax
There are the Following The simple About Create Laravel Live Search Using Ajax Full Information With Example and source code.
As I will cover this Post with live Working example to develop Laravel 5.8 Advance Live Search Box, so the laravel ajax get data from database for this example is following below.
Step-1 Create the Laravel Controller
php artisan make:controller LiveSearch
Step-2 LiveSearch.php
Simple Go to app\Controller\LiveSearch.php
namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; class LiveSearch extends Controller { function index() { return view('search_instant_live'); } function action(Request $request) { if($request->ajax()) { $output = ''; $query = $request->get('query'); if($query != '') { $data = DB::table('tbl_member')->where('MemberName', 'like', '%'.$query.'%') ->orWhere('Address', 'like', '%'.$query.'%') ->orWhere('City', 'like', '%'.$query.'%') ->orWhere('PostalCode', 'like', '%'.$query.'%') ->orWhere('Country', 'like', '%'.$query.'%') ->orderBy('MemberID', 'desc') ->get(); } else { $data = DB::table('tbl_member')->orderBy('MemberID', 'desc') ->get(); } $total_row = $data->count(); if($total_row > 0) { foreach($data as $row) { $output .= ''.$row->MemberName.''.$row->Address.''.$row->City.''.$row->PostalCode.''.$row->Country.''; } } else { $output = 'No Data Found'; } $data = array( 'table_data' => $output, 'total_data' => $total_row ); echo json_encode($data); } } }
Step-3 LiveSearch.blade.php
Create a View File (LiveSearch.blade.php)
Live search in laravel using AJAX - pakainfo.com
Live search in laravel using AJAX
Search Member DataTotal Data :
Member Name Address City Postal Code Country
Step- 4 Create View And define Controller
Laravel Set the Routes For display or View as well as Controller
Route::get('/search_instant_live', 'LiveSearch@index'); Route::get('/search_instant_live/action', 'LiveSearch@action')->name('search_instant_live.action');
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 Create Laravel Live Search Using 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.