php - Laravel 使用 @if 在页面之间切换
问题描述
我对 PHP 和 Laravel 还很陌生,我想弄清楚如何在“页面”之间切换可以这么说。
例如。如果没有创建文章,我想显示“没有创建文章”消息。否则,我想被重定向到不同的页面。
主页.blade.php
@if($category->articles= null)
<div class="container">
<p>There are no articles created</p>
</div>
@else
<div class="container">
<p> go to the main page </p>
</div>
@endif
家庭控制器
public function index(Category $category)
{
return view('home', [
'category' => $category
]);
}
任何想法将不胜感激。
解决方案
而不是 @if($category->articles= null) 使用 @if (count($category) > 0)
推荐阅读
- python - 如何使android应用程序作为服务器和python作为客户端
- google-kubernetes-engine - Traefik GKE 502 网关错误
- css - 垂直(鼠标)滚动使用溢出-x:滚动
- css - 如何在不出现 npm 错误的情况下将 sass 编译为 css
- java - 调用真实方法后,PowerMockito 模拟被清除
- image - 无法设置网络图像并出现错误“图像资源服务捕获的异常......”
- flutter - 自定义 Clipper Bezier 曲线 Flutter
- java - 使用反射获取 HashMap
- c# - UI 按钮引用在检查器中不可见
- elasticsearch - Elasticsearch - 条件字段或命名别名?