Laravel 在拉威尔搜索

Laravel 在拉威尔搜索,laravel,Laravel,我在Laravel中创建了一个简单的搜索,通过搜索词查找内容 控制器 刀片 @if(为空($data['books'])| |($data['authors'])) 未找到,请尝试使用其他搜索词 @恩迪夫 @foreach($data['books']作为$book) {{{$book->author->name} {{stru_limit($book->name,20)} @endforeach @forelse($data['authors']作为$author) {{stru_limit

我在Laravel中创建了一个简单的搜索,通过搜索词查找内容

控制器

刀片

@if(为空($data['books'])| |($data['authors']))
未找到,请尝试使用其他搜索词

@恩迪夫 @foreach($data['books']作为$book)

{{{$book->author->name}

{{stru_limit($book->name,20)} @endforeach @forelse($data['authors']作为$author)

{{stru_limit($author->name,20)} @endforeach
我想说的是

找不到,请尝试使用其他搜索词

当找不到搜索词时。但这对我不起作用

          @if(is_null(($data['books']) || ($data['authors'])))
                  <h2>Not Found, please try using another search term</h2><br/><br/>
          @endif
@if(为空($data['books'])| |($data['authors']))
未找到,请尝试使用其他搜索词

@恩迪夫

它不会返回未找到的

,这是因为即使没有结果,
$data['books']
$data['authors']
的值也不是空的,而是空的集合。因此,您应该检查结果的计数:

      @if(!$data['books']->count() || !$data['authors']->count())
              <h2>Not Found, please try using another search term</h2><br/><br/>
      @endif
此外,它实际上应该是一个国际海事组织:

或者使用
isEmpty()
方法:

      @if($data['books']->isEmpty() || $data['authors']->isEmpty())
              <h2>Not Found, please try using another search term</h2><br/><br/>
      @endif
      @if($data['books']->isEmpty() && $data['authors']->isEmpty())
              <h2>Not Found, please try using another search term</h2><br/><br/>
      @endif
@if($data['books']->isEmpty()&&&$data['authors']->isEmpty())
未找到,请尝试使用其他搜索词

@恩迪夫
谢谢,这太好了。
      @if($data['books']->isEmpty() || $data['authors']->isEmpty())
              <h2>Not Found, please try using another search term</h2><br/><br/>
      @endif
      @if($data['books']->isEmpty() && $data['authors']->isEmpty())
              <h2>Not Found, please try using another search term</h2><br/><br/>
      @endif