I am trying to select the last element from some JSON data but am getting an "Undefined Method" return. My code is to get the $order_serialized data from a specific Order and then to pick the $last_item in that JSON data and plug it into a dd() just for testing right now. If anyone could point out or explain where I went wrong it would be very much appreciated! Thank you so very much!
Controller:
public function getEdit($id){
$order = Order::where('id', '=', $id);
if($order->count()) {
$order = $order->first();
$order_serialized = json_decode($order->order_serialized);
$last_item = $order_serialized->last();
dd($last_item);
foreach($order->order_serialized as $key => $value){
$order->$key = $value;
}
return View::make('orders.edit')
->with('order', $order);
/*->with('last_item', $last_item);*/
} else {
return App::abort(404);
}
}