Please help with search script
$("#search").on("keyup",function(){
var search=$("#search").val();
search=search.replace(/ +/g, ' ');
if(search.length>=1){
var result=search.split("");
$.ajax({
type: 'POST',
url: "{{URL('/searchajax')}}",
data:
{
search:result
},
success: function(data) {
$("#searchresult").css("display","block");
if(data.length>0){
for(var i=0;i<data.length;i++){
$.each(data[i], function( index, value ) {
$("#itemssearch").append("<a href='{{URL('/product')}}/"+value.id+"'>\
<li>"+value.originalname+value.name+"</li>
\
</a>
\
");
});
}
}else{
...
}
}
});
}
});
public function searchajax(Request $request){
$search=$request->search;
$return=DB::table("products")
->where('originalname', 'like', '%'.$search.'%')
->orWhere('name', 'like', '%'.$search.'%')
->orderby("products.table_id")
->take(5)
->get();
return response()->json($return);
}
- if have search word "iphone 7s" how to search first "iphone" then "7s" and get all result in one variable
- if have search word "iphone 7s" how to search first "iphone" then "7s" and get all result in one variable