我有一个具有hasOne这样的关系的模型。
public function geoTournee()
{
return $this->hasOne(GeoTournee::class, 'id_tournee','id_tournee');
}
我已经加载了关系,并希望从集合中删除一个项目。
这里是结果,我想只获取行程内容并删除geo_tounee和其他字段。
"geo_tournee": {
"id_geo_tournee": 46,
"itineraire": [
{
"lat": 8000,
"lon": 3000,
"date": "2020:04:21 16:58:23"
},
{
"lat": 8000,
"lon": 3000,
"date": "2020:04:21 16:58:23"
},
{
"lat": 8000,
"lon": 3000,
"date": "2020:04:21 16:58:23"
},
{
"lat": 5000,
"lon": 9000,
"date": "2020:04:21 16:58:23"
},
{
"lat": 5000,
"lon": 9000,
"date": "2020:04:21 16:58:23"
},
{
"lat": 5000,
"lon": 9000,
"date": "2020:04:21 16:58:23"
}
],
"id_tournee": 33,
"created_at": "2020-04-23 18:10:32",
"updated_at": "2020-04-23 22:26:53"
任何这样做的想法!
只需使用此
return $this->hasOne(GeoTournee::class, 'id_tournee','id_tournee')->get('itineraire');