Laravel 5 belongsToMany如何在all()方法中获取数据;
Laravel 5 belongsToMany how to get the data in the method all();
我曾经属于 belongsToMany 关系
我试过
我的 Resta 型号
public function kitchens()
{
return $this->belongsToMany('App\Kitchen')->withTimestamps();
}
我的厨房模型
public function resto()
{
return $this->belongsToMany('App\Resto');
}
return恢复数据的功能
public function getAllRest($city)
{
$restos = Resto::latest('created_at')
->where('city','=', $city)
->get();
return $restos;
}
现在当我有一个接口关系时,它们的输出是怎样的?
其中一个我知道这样做是可能的
$resta = Resto::find($id);
$resta->kitchens->toArray();
如何在推导中输出所有数据?
已解决!
添加这个
$restos = Resto::latest('created_at')
->where('city','=', $city)
->get();
foreach($restos as $resto){
$resto->kitchens->toArray();
}
return $restos;
我曾经属于 belongsToMany 关系 我试过 我的 Resta 型号
public function kitchens()
{
return $this->belongsToMany('App\Kitchen')->withTimestamps();
}
我的厨房模型
public function resto()
{
return $this->belongsToMany('App\Resto');
}
return恢复数据的功能
public function getAllRest($city)
{
$restos = Resto::latest('created_at')
->where('city','=', $city)
->get();
return $restos;
}
现在当我有一个接口关系时,它们的输出是怎样的? 其中一个我知道这样做是可能的
$resta = Resto::find($id);
$resta->kitchens->toArray();
如何在推导中输出所有数据?
已解决! 添加这个
$restos = Resto::latest('created_at')
->where('city','=', $city)
->get();
foreach($restos as $resto){
$resto->kitchens->toArray();
}
return $restos;