首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >搜索框count():参数必须是数组或实现Countable的对象

搜索框count():参数必须是数组或实现Countable的对象
EN

Stack Overflow用户
提问于 2018-10-30 06:33:00
回答 1查看 148关注 0票数 0

我正在尝试写一个搜索代码,这是一个搜索方法:

代码语言:javascript
复制
public function searchcontent(){
    $searchkey = \Request::get('title');
    $customer = customers::where('customer_name','like','%'.$searchkey. '%')->orderBy('id')->paginate(5);
    return view('customers.search',['customer'=>$customer]);
}

这就是我们看到的

代码语言:javascript
复制
@if(count($customer)>0)
        @foreach($customer as $user)
            <tr>
                <td>{{$user->id}}</td>
                <th>{{$user->name}}</th>
                <th>{{$user->email}}</th>
                <th>{{$user->phone}}</th>
                <th>{{$user->city}}</th>
               <tr>
       @endforeach                     
            @endif


 <form class="form-header" action="{{url('tsearchcontent')}}" method="GET">
                    {{csrf_field()}}
                    <input class="au-input au-input--xl" type="text" name="title" placeholder=",,,,." />
                    <button class="au-btn--submit" type="submit">
                        <i class="zmdi zmdi-search"></i>
                    </button>
                </form>

我得到了这个error count():参数必须是一个数组或一个实现了Countable的对象

EN

回答 1

Stack Overflow用户

发布于 2018-10-30 06:37:42

在尝试调用count()之前,需要检查您的customer对象是否为空。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53054855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档