For Search
Functionality in laravel
1) In composer.json
file add below line:
"nicolaslopezj/searchable":
"1.*"
In
code: "require": {
"nicolaslopezj/searchable":
"1.*"
},
2) Update composer
after adding above line.
3) change config/databsae.php file as below:
change 'strict' => true
to 'strict' => false,
4) In model file add
below code:
use
Nicolaslopezj\Searchable\SearchableTrait;
class
Room extends Model
{
use
SearchableTrait;
protected
$searchable = [
'columns'
=> [
'name' => 10,
'morning_start'=>5,
'morning_end'=>5,
'afternoon_start'=>5,
'afternoon_end'=>5,
],
];
}
5) In Controller file
add code:
$serach_room = $request->input('serach_room'); // getting search text
if($serach_room){
$rooms_ids_clinic = $rooms_clinic->pluck((new
Room)->getTable().'.id');
$rooms =
Room::whereIn('id',$rooms_ids_clinic)->search($serach_room)-> paginate(env('NUM_ITEMS_PAGINATION',
10));
}else{
$rooms =
$rooms_clinic->paginate(env('NUM_ITEMS_PAGINATION', 10));
}
No comments:
Post a Comment