使用Laravel的Eloquent和eager loading如何检索built_load_cost数组和built_load_revenue数组中的值?
```
array:11 [▼
"id" => 5
"created_at" => "2018-03-24 00:19:52"
"updated_at" => "2018-03-24 00:20:14"
"load_number" => 1
"dispatcher_id" => 3
"carrier_id" => 826097731
"customer_id" => 1
"ip" => "127.0.0.1"
"deleted_at" => null
"built_load_cost" => array:6 [▼
"id" => 4
"created_at" => "2018-03-26 19:59:34"
"updated_at" => "2018-03-26 19:59:34"
"line_haul" => "100.00"
"extra_pickups" => "0.00"
"built_load_id" => 5
]
"built_load_revenue" => array:6 [▼
"id" => 4
"created_at" => "2018-03-26 19:59:43"
"updated_at" => "2018-03-26 19:59:43"
"line_haul" => "90.00"
"extra_pickups" => "0.00"
"built_load_id" => 5
]
]
```
答案 0 :(得分:0)
通过雄辩的模型访问价值时,请使用camelCase
,并带小写字母:
$load->builtLoadCost->line_haul
$load['builtLoadCost']['line_haul']
如果eloquent模型转换为数组,请使用snake_case
访问关系:
$load->toArray()['built_load_revenue']['line_haul']