【发布时间】:2014-11-10 21:33:25
【问题描述】:
目前,对于一个用户,我可以正确返回所有matches。
public function getMatches()
{
$matches = Criteria::whereUserId( Auth::id() )
->has('alerts')
->with('alerts.location', 'alerts.user.companies')
->get();
$this->layout->content = View::make('users.alert.matches',
array('matches' => $matches));
}
关系:
一个CriteriabelongsToMany Alerts 和一个AlertbelongsToMany Criterias。
问题:
如果用户希望查看有关某个匹配的更多信息,我想get 只是来自数据库的结果。在我看来,我可以访问第一个forloop 中的criteria_id,以及第二个forloop 中的alert_id。
@foreach($matches as $match)
{{$match->id}}
@foreach($match->alerts as $alert)
{{$alert->id}}
@endforeach
@endforeach
但是如何使用这些变量只选择一个用户想要查看更多信息的数据透视表匹配项?
如果用户要选择某个{{$alert->id}},我如何找到哪个criteria_id 与该alert_id 相关,然后查询数据库以返回刚刚那一行信息,两者都来自@ 987654332@ 表和alert 表,以及上面显示的with-> 语句。
非常感谢您的帮助。
【问题讨论】:
标签: php laravel laravel-4 eloquent pivot-table