Sid Heart Sid Heart - 4 months ago 13
PHP Question

How to show my only Blog Who related with tags

i am using This package for tag my blog my Laravel 5.2 App

https://github.com/cviebrock/eloquent-taggable


now i want to show only that blog who related with tag
i am trying to do like this here is my route.php

Route::get('blog/category/{category}', [
'uses' => 'BlogController@categoryindex',
'as' => 'category.index'
]);


Here is my controller

public function categoryindex($slug){

$blogs = blog::where('normalized', $slug)->withAnyTags();

return view('blog.categoryindex', compact('blogs'));

}


Here is my blog.categoryindex.blade.php

@foreach($blogs as $blog)
<h1>{{ $blog->title }}</h1>
@endforeach


but its won't work

Answer

I haven't used this package - nor have I tested, but based on the documentation, I think you're looking for this:

$blogs = Blog::withAnyTags($slug)->get(); //this is correct

@foreach($blogs as $blog)
    <h1>{{ $blog->title }}</h1>
@endforeach

It'd be helpful is you dd($blogs) and show me the result.