我用的是Laravel5.2。
我的问题是:
变量可以分类吗?
例如:
有一个控制器,它可以获取属于当前用户的所有文章,如下所示:
public function index()
{
$user=\Auth::user();
$articles = $user->articles;
return view('user.dashboard.index', compact('articles'));
}鉴于此,下面的代码可以显示如下文章:
<div class="card">
<div class="card-header">
Articles
</div>
@if ($articles!=null)
<table class="table table-sm">
<thead>
<tr>
<th>title</th>
<th>created time</th>
<th>status</th>
</tr>
</thead>
<tbody>
@foreach ($articles as $article)
<tr>
<td>{{$article->title}}</td>
<td>{{$article->created_at}}</td>
<td>{{$article->status}}</td>
</tr>
@endforeach
</tbody>
</table>
@else
<p>Nothing</p>
@endif
</div>这些文章可分为两类:
1“已发布”,状态为1。
2状态为0的、“未发布”。
问题:
我希望将已发表的文章显示在卡片中(div class=" card "),而未发表的文章则显示在另一张卡中。
他们能被分类吗?因此,它不需要查询两次。
发布于 2016-04-26 17:54:33
https://stackoverflow.com/questions/36872175
复制相似问题