mercredi 24 janvier 2018

Laravel Sort Results by Query and URL

I want sort my Search Results with an URL. I cant use Controller in my way because i use Route for /search.

My Search Route:

Route::any ( '/search', function () {
    $q = Input::get ( 'q' );

    $sort = Product::where ( 'name', 'LIKE', '%' . $q . '%' )->orderBy('created_at','desc')->paginate(20);


    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 );
    }

Now i want create an Button where i can Sort the results from query search.

Button Example:

<a href="/search?q=">Sort by Price</a>

I want add like this to my Route:

$sort = Product::where ( 'name', 'LIKE', '%' . $q . '%' )->orderBy('created_at','desc')->paginate(20);

This dont work.. And then add the behind my Button URL like:

<a href="/search?q=&`">Sort by Price</a>

Any Idea how i can do it correct? Sorry i am an Beginner with Laravel and i know its not correct.

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire