Laravel 拉威尔雄辩的关系和观点
我试图以本线程中显示的表为例展示一个结构: 我想用这个例子在一页index.blade.php中展示如下内容:Laravel 拉威尔雄辩的关系和观点,laravel,eloquent,Laravel,Eloquent,我试图以本线程中显示的表为例展示一个结构: 我想用这个例子在一页index.blade.php中展示如下内容: Category 1 Post1.Category1 Post2.Category1 Category 2 Post1.Category2 Post2.Category2 Post3.Category2 Post4.Category2 Category 3 Post1.Category3 我不知道我需要从控制器传递哪些
Category 1
Post1.Category1
Post2.Category1
Category 2
Post1.Category2
Post2.Category2
Post3.Category2
Post4.Category2
Category 3
Post1.Category3
我不知道我需要从控制器传递哪些数组
我可以得到类别列表,但如何为每个类别的职位
谢谢
任何想法你只需要通过类别和他们的帖子。这很简单 控制器 看法
重新表述您的问题并格式化代码,以便我们知道您需要什么。
$categories = Category::with('posts')->get();
return View::make('some.view')->with('categories', $categories);
@foreach($categories as $category)
{{{ $category->name }}}
@foreach($category->posts as $post)
{{{ $post->name }}}.{{{ $category->name }}}
@endforeach
@endforeach