3

I'm trying to acces to the parameters of an array, and not been able to. I get an array through this eloquent statement:

$plazas = DB::table('clase_schedule')->select(['schedule_id', DB::raw('SUM(capMax)')])->groupBy('schedule_id')->get();

What returns me this array:

array:2 [▼
  0 => {#465 ▼
    +"schedule_id": "2"
    +"SUM(capMax)": "221"
  }
  1 => {#464 ▼
    +"schedule_id": "3"
    +"SUM(capMax)": "12"
  }
]

I've tryed serveral things to acces to the schedule_id and SUM(capMax) values, but nothin.

@foreach($plazas as $id => $id)
{{$id[0]}}<br/>
@endforeach

With that i get the return value of 0 1

1
  • 1
    @foreach($plazas as $plaza) {{$plaza->schedule_id}} @endoreach Commented Mar 14, 2016 at 8:57

1 Answer 1

6

Use alias to fetch query

$plazas = DB::table('clase_schedule')->select(['schedule_id', DB::raw('SUM(capMax) as capmax')])->groupBy('schedule_id')->get();

Blade

@foreach($plazas as $plaza)
{{ $plaza['capmax'] }}<br/>
@endforeach
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.