我正在尝试编写搜索代码 这是搜索方法:
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的数组或对象
答案 0 :(得分:1)
在尝试调用count()之前,需要检查客户对象是否为空。