Please check the below code for view and controller.
Controller:
$staffreply = StaffReply::where('ticket_id', '=', $ticketID)->orderBy('id', 'asc')->get();
if ($staffreply->count()) {
//Get the data values
} else {
$staffreply = "";
$supportstaff = "";
$supportteam = "";
}
return view('pages/support/service-view',compact('data','staffreply','supportstaff','supportteam'));
View Page:
@if($staffreply->count())
@foreach($staffreply as $supportDesk)
<span>Posted on {{$supportDesk->created_date;}}</span>
@endforeach
@endif
Error:
Call to a member function count() on int (View: --\htdocs\laravel\project\resources\views\pages\support\service-view.blade.php)
How to solve the issue.
CodePudding user response:
Even though it is not clear what $staffreply
is. You can't use count()
on non-Arrayables.
First make sure that $staffreply
is in fact a collection in the controller. If not, the fallback in the else
should probably equal an empty collection and not a 0. If so, in the view you wouldn't need to check if $staffreply->count()
.
CodePudding user response:
Thanks for the support, after I have edited the view page code issue solved.
Edited Code
@if($staffreply!="")
@foreach($staffreply as $supportDesk)
<span>Posted on {{$supportDesk->created_date;}}</span>
@endforeach
@endif