php - convert array to object in laravel
33
i'm trying to convert php array to object and i want to get it in my blade.
this is my code that my array is created
$related_dock = DB::table('reserve')
->join('product_dock', 'reserve.product_id', '=', 'product_dock.product_id')
->join('dock', 'product_dock.dock_id', '=', 'dock.id')
->select([DB::raw('count(dock_id) as used'), 'dock.dock_name as dock name'])
->groupBy('dock_id')
->orderBy('used', 'desc')
->get();
return $related_dock;
and my blade is this
@foreach($related_dock as $related_docks)
{{ $related_docks }}
@endforeach
and this code return below array
Collection {#1365 ▼
#items: array:3 [▼
0 => {#1364 ▼
+"used": 2
+"dock name": "Bebek"
}
1 => {#1376 ▼
+"used": 2
+"dock name": "sisli"
}
2 => {#1378 ▼
+"used": 1
+"dock name": "Beshiktash"
}
]
}
but i want use this array as object like this
@foreach($related_dock as $related_docks)
{{ $related_docks->used }}
@endforeach
Answer
Solution:
You can do like this, please check