1

鉴于以下要点:https ://gist.github.com/atrauzzi/6674488eb4fbd7a45671

Users have and belong to many Applications.

Applications have many PushMessages.

PushMessages belong to one Application.

我希望能够为与用户相关的每个应用程序获取所有 PushMessage。

QueryCode.php要点来看,我必须改变什么才能让事情正常进行?

4

2 回答 2

0
PushMessage::leftJoin(Application::getTable(), Application::getTable().'.id', '=', PushMessage::getTable().'.application_id')->leftJoin(...)->where(Application::getTable().'.user_id','=',1)->select(PushMessage::getTable().'.*')->get();

Eloquent 实际上只是将方法调用卸载到 fluent 查询构建器。虽然,我建议将此特定查询包装在一个方法中,或将其放入存储库中

于 2013-03-24T20:11:30.350 回答
0

我会使用 PushMessage 类来查询它们。

$user = User::find(Auth::user()->id);
$pushMessages = PushMessage::whereIn('application_id', $user->applications()->lists('id'));
于 2013-03-24T17:30:52.487 回答