Reputation: 161
i'm trying to write a search code this is search method:
public function searchcontent(){
$searchkey = \Request::get('title');
$customer = customers::where('customer_name','like','%'.$searchkey. '%')->orderBy('id')->paginate(5);
return view('customers.search',['customer'=>$customer]);
}
and this is the view
@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>
and i got this error count(): Parameter must be an array or an object that implements Countable
Upvotes: 0
Views: 152
Reputation: 974
You need to check whether or not your customer object is null before trying to invoke count().
Upvotes: 1