thank salenn-m but not work show this error
Object of class stdClass could not be converted to string
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 --}}
@endforeach
or probably simpler just reference the wanted property
{{ $oSales['xxx'] }}
or access the object
{{ $oSales->xxx }}
Hope that helps.
Thanks goedda but I know but the problem from using count
->select(DB::raw('COUNT(sales.id_user)'))
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')
->join('users','users.id','=','sales.id_user')
->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')
->join('users','users.id','=','sales.id_user')
->select(DB::raw('COUNT(sales.id_user) as count'))
->where('sales.id_user','=',$dIdAgent )->count();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community