Laravel 深入了解拉威尔雄辩的人际关系

Laravel 深入了解拉威尔雄辩的人际关系,laravel,laravel-5,eloquent,Laravel,Laravel 5,Eloquent,我的问题分为两部分: 1) 我正在尝试获取特定事件,其中rsvps=登录的用户\u id。 2) 然后过滤需要查询关系的事件日期。您正在尝试查询事件 $favorites = Event::whereHas('rsvps', function($q) { $q->where('user_id', 1) })->find('id'); // Passing in 'id' won't work here, it should be the actual id of an e

我的问题分为两部分:

1) 我正在尝试获取特定事件,其中rsvps=登录的用户\u id。
2) 然后过滤需要查询关系的事件日期。您正在尝试查询
事件

$favorites = Event::whereHas('rsvps', function($q) {
    $q->where('user_id', 1)
})->find('id');   // Passing in 'id' won't work here, it should be the actual id of an event.

令人惊叹的!非常感谢
with
负责快速加载数据,与实际查询RSVP上有限制的事件无关。您正在查找
has
而不是我的修订代码正在拾取所有事件,而不仅仅是具有特定id的事件:
$myFavs=Event::with(['rsvps'=>函数($q){$q->where('user_id',2);}])->get()我能够使用它:
$myFavs=Event::whereHas('rsvps',function($q){$q->where('user_id',2);})->get()谢谢大家!!
[
{"id":1,"user_id":"1","created_at":"2016-03-01 02:26:48","updated_at":"2016-03-01 02:26:48","event_name":"Awesome Event","event_venue":"The Rainbow Room","address":"612 Rachael Ln.","event_details":"Epic","event_date":"03\/12","image":"2016-03-01-02-26-48-heartHands.jpg","time":"8:00",
"rsvps":[
{"id":1,"created_at":"2016-03-01 02:28:39","updated_at":"2016-03-01 02:28:39","event_id":"1","user_id":"1"}]
},

{"id":2,"user_id":"1","created_at":"2016-03-01 02:40:05","updated_at":"2016-03-01 02:40:05","event_name":"New Event","event_venue":"My House","address":"612 Rachael Ln.","event_details":"Epic","event_date":"03\/01","image":"2016-03-01-02-40-05-img3.jpg","time":"8:00",
"rsvps":[
{"id":2,"created_at":"2016-03-01 02:40:12","updated_at":"2016-03-01 02:40:12","event_id":"2","user_id":"1"},

{"id":3,"created_at":"2016-03-01 22:21:33","updated_at":"2016-03-01 22:21:33","event_id":"2","user_id":"2"}
]}
]
$favorites = Event::with('rsvps')->find('id')->where('rsvps->user_id', '1')->get();
$favorites = Event::whereHas('rsvps', function($q) {
    $q->where('user_id', 1)
})->find('id');   // Passing in 'id' won't work here, it should be the actual id of an event.