0

I have a Query in laravel 4 query builder which calculates a count(). it has a result as I dump its data. but I can't get its integer value.

here is my Query:

$data['provinces'] = DB::Table('doctors')
                        ->join('provinces', 'doctors.province_id', '=', 'provinces.id')
                        ->select('doctors.province_id','provinces.name as name',DB::raw("COUNT('doctors.province_id')"))
                        ->whereIn('doctors.id', $ids)
                        ->groupBy('doctors.province_id')
                        ->get();

here is my code in blade :

@foreach($data['provinces'] as $province)
    <a href="#" class="list-group-item">{{$province->toArray()["name"]}}<span class="badge">{{$province->toArray()["COUNT('doctors.province_id')"]}}</span></a>
@endforeach

and here is my dd($province) :

object(stdClass)#582 (3) {
  ["province_id"]=>
  int(8)
  ["name"]=>
  string(10) "تهران"
  ["COUNT('doctors.province_id')"]=>
  int(1)
}

How to fetch data from ["COUNT('doctors.province_id')"] in blade. Thanks for help

1 Answer 1

1

You already fetch the provinces.name as name - you can do the same for the count:

DB::raw("COUNT('doctors.province_id') as mycount")

Then, all you need to do to get it is $province->mycount.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.