Support the ongoing development of Laravel.io →
Eloquent Views
Last updated 2 years ago.
0

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

0

thank salenn-m but not work show this error

Object of class stdClass could not be converted to string
0

try:

{{ dd($oSales) }}

and see what you get.

0

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

0

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.

Last updated 9 years ago.
0

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

0

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();
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.