【发布时间】:2017-11-13 07:50:53
【问题描述】:
我有一个数据透视表country_team,其中包含这种形式的数据
国家队
country_id team_id
1 1
1 2
国家
id name
1 Spain
团队
id name
1 Barcelona
2 Real Madrid
在我的表格中,我以这种形式显示它
表格
Country_id Team
1 Barcelona
1 Real Madrid
现在,我想将皇家马德里从行中分离出来,但是如何获取皇家马德里的 id 或获取名称 Real Madrid 来分离它。我无法使用 country_id 删除,因为它会删除属于该特定国家/地区的所有团队。
控制器
public function index()
{
$countries = Country::where('id',Auth::user()->id)->get();
return view('admin.order.index',compact('orders'));
}
public function deleteTeam()
{
$get_country_id = Country::findOrFail($id);
$get_country_id->teams()->detach();
}
HTML
<tbody>
@foreach($countries as $country)
@foreach($country->teams as $team)
<tr>
<td>{{$country->id }}</td>
<td>{{ $team->name}}</td>
</tr>
@endforeach
@endforeach
</tbody>
【问题讨论】: