Skip to content Skip to sidebar Skip to footer

Laravel 5.2 Filter With Dropdownlist

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. I dynamically generate drop-d

Solution 1:

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:

publicfunctionshow($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.

Post a Comment for "Laravel 5.2 Filter With Dropdownlist"