Reputation: 2647
iam receving this error, htmlentities()
expects parameter 1 to be string, object given. How to solve it?
My controller
public function category()
{
$recordsByCategories=\DB::table('products')
->select('categories', \DB::raw('count(*) as total'))
->groupBy('categories')
->get();
//dd($recordsByCategories);
return view('dashboard.show',compact('recordsByCategories'));
}
my view
@foreach($recordsByCategories as $recordsByCategory)
{!!$recordsByCategory->$categories!!}
@endforeach
Upvotes: 0
Views: 732
Reputation: 21535
try this in view
use {{$recordsByCategory->categories}}
instead of {{$recordsByCategory}}
It is because $recordsByCategory
is an object
One another problem here is, when you use count(*)
in this query then it will return only one row in result.
Upvotes: 1
Reputation: 44823
$recordsByCategory
is an object, not a string, so {{$recordsByCategory}}
makes no sense. You want to display properties of the record, not the entire record itself.
Upvotes: 0