Laravel 5.2 filter with dropdownlist

前端 未结 1 556
再見小時候
再見小時候 2021-01-24 09:24

I want to make drop-down list filtering.

I have a web page, that shown some post with title and categories.

The page has a drop-down in nav.blade.php

相关标签:
1条回答
  • 2021-01-24 09:59

    This would get you started:

    Assuming you have a route like:

    Route::get('/{category_id}', ['as'=>'home', 'uses'=>'PostController@show']);
    

    In the PostController@show method:

    public function show($category_id)
    {
        $categories = Category::all();
        $selected_category = Category::with('posts')->where('id', $category_id)->first();
        $posts = $selected_category->posts;
    
        return redirect()->back()->with(compact('posts', 'categories'));
    }
    

    You can change the redirect location.

    0 讨论(0)
提交回复
热议问题