Its Possible to make an Search filter with an Button click?
Thats what i have try and i think its work in this way:
I have in the Menu one Search Input Field and after i search an Word i see the results + the Sortby Button.
Route for Search:
Route::any ( '/search', function () {
$q = Input::get ( 'q' );
if($q != ""){
$products = Product::where ( 'name', 'LIKE', '%' . $q . '%' )->orWhere ( 'description', 'LIKE', '%' . $q . '%' )->paginate (200)->setPath ( '' );
$pagination = $products->appends ( array (
'q' => Input::get ( 'q' )
) );
if (count ( $products ) > 0)
return view ( 'search' )->withDetails ( $products )->withQuery ( $q );
}
$s = Input::get ( 's' );
if($s != ""){
$products = Product::where ( 'name', 'LIKE', '%' . $s . '%' )->orWhere ( 'description', 'LIKE', '%' . $s . '%' )->paginate (200)->setPath ( '' );
$pagination = $products->appends ( array (
's' => Input::get ( 's' )
) );
if (count ( $products ) > 0)
return view ( 'search' )->withDetails ( $products )->withQuery ( $q );
}
return view ( 'search' )->withMessage ( 'We dont found any Products with your search query. Please try again !' );
} );
The $s
is what i have added now to try the Button:
$s = Input::get ( 's' );
if($s != ""){
$products = Product::where ( 'name', 'LIKE', '%' . $s . '%' )->orWhere ( 'description', 'LIKE', '%' . $s . '%' )->paginate (200)->setPath ( '' );
$pagination = $products->appends ( array (
's' => Input::get ( 's' )
) );
if (count ( $products ) > 0)
return view ( 'search' )->withDetails ( $products )->withQuery ( $q );
}
My $s
Button:
<form action="/search" method="get">
Choose your favorite subject:
<button name="q" type="submit" value="">HTML</button>
</form>
The value from the Button is default only value=""
I have added also to it but first i must change the $s
Route of Course later that i can Products sortby for example created_at
.
I want an Url like this: /search?q=mysearchword&s=createdat
Possible?
If yes how i can add the &
after q=mysearchword
and what i must write in my Route instead of $s = Input::get ( 's' );
because its not an input.
Many Thanks!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire