我正在尝试写一个搜索代码,这是一个搜索方法:
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>我得到了这个error count():参数必须是一个数组或一个实现了Countable的对象
发布于 2018-10-30 06:37:42
在尝试调用count()之前,需要检查您的customer对象是否为空。
https://stackoverflow.com/questions/53054855
复制相似问题