Today, We want to share with you Laravel Eloquent Search Filter.In this post we will show you How to implement search function in Laravel 6.2, hear for Searching models using a where like query in Laravel 6 we will give you demo and example for implement.In this post, we will learn about Build a live search feature with Laravel 6.2 and Vue.js with an example.
Laravel Eloquent Search Filter
There are the Following The simple About Create Live Search In Laravel Using AJAX Full Information With Example and source code.
As I will cover this Post with live Working example to develop laravel search multiple columns, so the Writing advanced Eloquent search query filters is used for this example is following below.
Step 1: Define a Laravel Route
routes/web.php
Route::get('/find', '[email protected]'); Route::post('/retrivetickets', '[email protected]');
tep 2: Create Controller and Source code:-
Laravel Create Controller
php artisan make:controller TicketController
TicketController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use App\Ticket; use App\view; use Illuminate\Support\Facades\Route; use Validator, Redirect; use Illuminate\Support\Facades\Auth; use Session; use Illuminate\Support\Facades\Input; class TicketController extends Controller { public function find() { return view('tickets_list'); } public function retrivetickets() { $search = Input::get ( "search" ); $tickets = Ticket::where ( 'name', 'LIKE', '%' . $search . '%' )->orWhere ( 'destination', 'LIKE', '%' . $search . '%' )->get (); if (count ( $tickets ) > 0) return view ( 'tickets_list' )->withDetails ( $tickets )->withQuery ( $search ); else return view ( 'tickets_list' )->withMessage ( 'No tickets Details found. Try to search again !' ); } }
Step 3: Laravel Model code:-
Ticket.php
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Ticket extends Model { protected $table = 'tickets'; protected $fillable = ['name','tid','destination','tnuom','pickup_dt']; }
Step 4: view Source code
tickets_list.blade.php
<!doctype html> <html> <head> <style> </style> </head> <body> <form method="post" action="http://www.domain_name.uk/projet_folder/blog/public/retrivetickets"> <input type="text" name= "search"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> <button>Search Now</button> </form> <?php if(isset($details)){ ?> <table class="table table-striped"> <thead> <tr> <th>Name</th> <th>Destination</th> </tr> </thead> <tbody> @foreach($details as $user) <tr> <td>{{$user->name}}</td> <td>{{$user->destination}}</td> </tr> @endforeach </tbody> </table> <?php } ?> </body> </html>
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 search form get method.
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.