【问题标题】:search box count(): Parameter must be an array or an object that implements Countable搜索框count():参数必须是数组或者实现了Countable的对象
【发布时间】:2019-04-02 22:29:28
【问题描述】:

我正在尝试编写搜索代码 这是搜索方法:

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

这就是风景

@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>

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

【问题讨论】:

    标签: laravel


    【解决方案1】:

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

    【讨论】:

    • 你的意思是在数据库中?
    • 不,在您的代码中。检查它是否为空这里是参考stackoverflow.com/questions/41269198/…
    • 我添加了它。它显示了相同的错误消息@dustinos3
    猜你喜欢
    • 2018-06-28
    • 2019-08-03
    • 2018-06-08
    • 2018-09-22
    • 1970-01-01
    • 2018-11-26
    • 2020-04-27
    • 2021-11-05
    • 2019-10-04
    相关资源
    最近更新 更多