Support the ongoing development of →
Eloquent Views
Last updated 10 months ago.

If you need only one value, then instead ->get() put ->first()


thank salenn-m but not work show this error

Object of class stdClass could not be converted to string


{{ dd($oSales) }}

and see what you get.


sgoodwin10 thanks dd the same var_dump($oSales) its work but I need show value just not format var_dump


Just an educated guess, but the doc states:

All multi-result sets returned by Eloquent, either via the get method or a relationship, will return a collection object. This object implements the IteratorAggregate PHP interface so it can be iterated over like an array

This means that with the 'get' method (and with the 'first' method as well), you will get a collection of objects or a single object. Due to the PHP interface you can access the object or the single object like an array.

In other words: You are most likely passing an object/array to your view and this can not be accessed like a string.

Either transform the object/array to a string value and pass this one then to the view, or iterate in the view and select the value then there. Having more information is usually an advantage, thus, I would suggest to iterate in the view. Something like this:

@foreach ($oSales as $property)
    <p>This is property {{ $property->xxx }}</p> {{-- replace 'xxx' with your wanted property --}}

or probably simpler just reference the wanted property

{{ $oSales['xxx'] }}

or access the object

{{ $oSales->xxx }}

Hope that helps.

Last updated 8 years ago.

Thanks goedda but I know but the problem from using count


if replace count other any one its work but stay using count not work Thanks


Your code is passing an array to the view, this needs to be converted to a string first. This simplest way is probably using pluck.

$oSales =DB::table('sales')
            ->select(DB::raw('COUNT(sales.id_user) as count'))
            ->where('sales.id_user','=',$dIdAgent )->pluck('count');

EDIT: Better yet, just use the count aggregate:

$oSales =DB::table('sales')
            ->select(DB::raw('COUNT(sales.id_user) as count'))
            ->where('sales.id_user','=',$dIdAgent )->count();
Last updated 8 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.