如何显示我唯一的博客谁与标签相关


How to show my only Blog Who related with tags

我正在使用这个包来标记我的博客我的Laravel 5.2应用程序

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

现在我只想显示与标签相关的博客我正在尝试这样做,这是我的路线.php

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

这是我的控制器

public function categoryindex($slug){
    $blogs = blog::where('normalized', $slug)->withAnyTags();
    return view('blog.categoryindex', compact('blogs'));
}

这是我的博客.categoryindex.blade.php

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

但它不起作用

我没有

使用过这个包 - 也没有测试过,但根据文档,我认为你正在寻找这个:

$blogs = Blog::withAnyTags($slug)->get(); //this is correct
@foreach($blogs as $blog)
    <h1>{{ $blog->title }}</h1>
@endforeach

如果您dd($blogs)并向我展示结果会很有帮助。