{
"data":[
{
"id":229,
"name":"Alax",
"age":31,
"type":"1",
"address":[
{
"id":22,
"street_add":"14 New York",
"country":null,
"country": [{
"id":1,
"name":"USA",
"code":"US",
"created_at":null,
"updated_at":null
}]
}
]
},
{
"id":230,
"name":"Jon",
"age":21,
"type":"1",
"address":[
{
"id":23,
"street_add":"25 Miami",
"country":null,
"country": []
}
]
}
]
}
if ($address) {
Model::has('address.country', '>', 0);
} else {
Model::has('address.country', '<=', 0);
}
尝试模型::有,但对我不起作用。
我如何获取地址是否包含国家/地区。我尝试过此代码对我不起作用,请您对此提出建议。
谢谢。
答案 0 :(得分:0)
就像文档一样: enter link description here
if ($address) {
$address = Model::has('address.country', '>', 0)->get();
} else {
$address = Model::has('address.country', '<=', 0)->get();
}