Php 如何在Laravel中显示所有类别
我试图在单刀片上显示数据库中的所有类别,但是,我也会在数据库中显示五个类别作为我的导航菜单。我不确定这可能是我使用的循环,因为我一直得到五个类别,而不是所有类别Php 如何在Laravel中显示所有类别,php,laravel,laravel-5.1,Php,Laravel,Laravel 5.1,我试图在单刀片上显示数据库中的所有类别,但是,我也会在数据库中显示五个类别作为我的导航菜单。我不确定这可能是我使用的循环,因为我一直得到五个类别,而不是所有类别 公共功能索引() { 返回视图('index')->带有('title',Setting::first()->站点名称) ->with('categories',Category::take(5)->get() ->with('first_post',post::orderBy('created_at','desc')->first()
公共功能索引()
{
返回视图('index')->带有('title',Setting::first()->站点名称)
->with('categories',Category::take(5)->get()
->with('first_post',post::orderBy('created_at','desc')->first())
->with('second_post',post::orderBy('created_at','desc')->skip(1)->take(1)->get()->first())
->with('third_post',post::orderBy('created_at','desc')->skip(2)->take(1)->get()->first())
->使用('wordpress',类别::查找(4))
->带有('laravel',类别::find(3))
->使用('settings',Setting::first());
}
这是我的单柱控制器的代码
公共函数singlePost($slug)
{
$post=post::where('slug',$slug)->first();
$next_id=Post::where('id','>',$Post->id)->min('id');
$prev_id=Post::where('id','我认为应该在“categories”的索引查询中更改var名称。类似于
->with('categories\u to\u navigation',Category::take(5)->get())
。
如果视图single.blade.php
extendindex.blade.php
此变量名称被覆盖。你的印象是什么take(5)
做了什么?take(5)返回数据库中的5个类别问题解决了,我实际上没有这样想。谢谢@juan。