I am trying to query database using the user input value for search field. But the result i am getting is totally wrong. It doesn't have the search term. I have no idea where i could be doing wrong. i followed the laravel doc
,and some questions over stackoverflow
, but nothings seems to be working. Can anyone please check my query and perhaps can guide me to the right direction.
My query is like this Query
term is Rose
, and only one record has title name Rose
public function catelogSearch(Request $request){
if ($request->has('query') && $request->get('query')!= ''){
$searchQuery = $request->get('query');
$query = ProductCategory::with(['product'=>function($q) use($searchQuery){
$q->where([
['product_type','both'],
['title','LIKE','%'.$searchQuery.'%'],
]);
if(request()->segment(1)=='shopping'){
$q->orWhere('product_type','shop');
}elseif (request()->segment(1)=='subscription'){
$q->orWhere('product_type','sub');
}
$q->whereHas('price',function ($q){
$q->where('quantity','>',0);
$q->where('status',1);
});
}])->with('product');
$data['result']=$query->paginate(30)->toArray();
print_r($data);
}
This query giving me all the data in my database, unlike where it should give me where it has the query term in the title. And also please see, that i am querying with('product')
two times. If i do one time, It doesn't return product data, it return empty response for the product.
Can anyone please suggest me. Thank u.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire