我收到此错误消息,我不知道我的代码有什么问题。
CategoriesController.php
class CategoriesController extends Controller
{
public function index()
{
$categories = Category::all();
return view('admin.categories.index', ['categories' => $categories]);
}
}
index.blade.php
foreach ($categories as $category)
<tr>
<td>{{$category->idcat}}</td>
<td>{{$category->cat}}</td>
<td>
<a href="edit.html" class="fa fa-pencil"></a>
<a href="#" class="fa fa-remove"></a>
</td>
</tr>
endforeach
答案 0 :(得分:3)
这不是刀片模板引擎的工作方式: 您应该在视图中使用@foreach @endforeach:
@foreach ($categories as $category)
<tr>
<td>{{$category->idcat}}</td>
<td>{{$category->cat}}</td>
<td><a href="edit.html" class="fa fa-pencil"></a> <a href="#" class="fa fa-remove"></a></td>
</tr>
@endforeach