从Laravel中的数组对象数组获取数据 [英] Get data from array of array object in laravel

查看:207
本文介绍了从Laravel中的数组对象数组获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据:

[{"order_id":37,"order_code":"Order00003","user_id":1,"full_name":"Duc.VUong","phone":"01203388870","address":"445\/33b b\u00ecnh \u0111\u00f4ng","recieve_address":"445\/33b b\u00ecnh \u0111\u00f4ng","total_product":2,"total_price":1450000,"status":0,"created_at":"2017-04-12 17:01:38","updated_at":"2017-04-12 17:01:38","detail_orders":[{"id":29,"order_id":37,"order_code":"Order00003","product_id":1,"price":800000,"quantity":1,"total_amount":800000,"created_at":"2017-04-12 17:01:38","updated_at":"2017-04-12 17:01:38","product":[{"product_id":1,"product_name":"H\u01b0\u01a1ng N\u1eafng","product_type_id":1,"price":800000,"description":"H\u01b0\u01a1ng n\u1eafng g\u1ed3m c\u00f3:hoa h\u1ed3ng da t\u1ea1o n\u00ean gam m\u00e0u nh\u1eb9 nh\u00e0ng nh\u01b0ng kh\u00f4ng k\u00e9m ph\u1ea7n thu h\u00fat. Th\u00edch h\u1ee3p \u0111\u1ec3 t\u1eb7ng ch\u00fac m\u1eebng, sinh nh\u1eadt, k\u1ec9 ni\u1ec7m,...","product_image":"2385_huong-nang.jpg","addition_information":"H\u01b0\u01a1ng n\u1eafng g\u1ed3m c\u00f3:\r\n\r\n- Hoa h\u1ed3ng da\r\n\r\n- Hoa t\u00fa c\u1ea7u\r\n\r\n- Hoa baby\r\n\r\n- Hoa l\u00e1 ph\u1ee5 kh\u00e1c","status":1,"created_at":null,"updated_at":null}]},{"id":30,"order_id":37,"order_code":"Order00003","product_id":2,"price":650000,"quantity":1,"total_amount":650000,"created_at":"2017-04-12 17:01:38","updated_at":"2017-04-12 17:01:38","product":[{"product_id":2,"product_name":"My everything","product_type_id":1,"price":650000,"description":"\u201cYou are my everything You are enough and the best for me\u201d L\u1eddi b\u00e0i h\u00e1t nh\u01b0 \u0111\u00e3 n\u00f3i l\u00ean t\u00e2m t\u01b0 c\u1ee7a nh\u1eefng tr\u00e1i tim \u0111ang y\u00eau, ng\u1ecdt ng\u00e0o v\u00e0 l\u00e3ng m\u1ea1n v\u00f4 c\u00f9ng. B\u00f3 hoa \u201cMy everything\u201d c\u0169ng nh\u01b0 th\u1ebf, \u0111\u00e1ng y\u00eau v\u00e0 t\u01b0\u01a1i s\u00e1ng. Th\u00edch h\u1ee3p t\u1eb7ng sinh nh\u1eadt, k\u1ec9 ni\u1ec7m, v.v\u2026","product_image":"2511_mat-ngot.jpg","addition_information":"B\u00f3 hoa \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf t\u1eeb:\r\n\r\n-         25 hoa h\u1ed3ng \u0111\u1ecf\r\n\r\n-         Hoa baby tr\u1eafng\r\n\r\n-         Hoa l\u00e1 ph\u1ee5 kh\u00e1c","status":0,"created_at":null,"updated_at":null}]}]}]

我的代码

@extends('templates.master')
@section('content')
<div class="container">
    @foreach ($orders as $order)
    @php
    echo "
    <pre>";
    $arr=array();
    $arr= $order->detail_orders;

    @foreach ($arr as $item)
    echo $item->id;
    @endforeach
    echo "</pre>";
    @endphp
    @endforeach 
    @stop
</div>

当我回显$ arr时,它具有数据,但是到第二个foreach时,我得到消息: FatalErrorException in 04212fe3982c22912d313c7bbaa7970ed5d682e8.php line 10: syntax error, unexpected '<' 那么,如何获取ID以在视图中显示呢?

when i echo $arr, it have data, but to second foreach, i get message: FatalErrorException in 04212fe3982c22912d313c7bbaa7970ed5d682e8.php line 10: syntax error, unexpected '<' So, how can i get the id in this for show it in view?

推荐答案

如果要将数组对象数据转换为数组.这很简单.您首先会获得所有记录.类似的事情:

If you want to convert array object data in to array. This is very simple. You first get all the records.Something like that:

$orders = DB::table('orders')->get(); //get all records form table
$orders = json_decode(json_encode($orders),true);// this will convert data into array
echo "<pre>"; print_r($orders); die; // now echo

然后您可以在刀片文件中使用foreach

and after that you can use foreach in blade file

这篇关于从Laravel中的数组对象数组获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆