首页 > 解决方案 > 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
        ]);
    }

任何想法将不胜感激。

标签: phplaravel

解决方案


而不是 @if($category->articles= null) 使用 @if (count($category) > 0)


推荐阅读