【发布时间】:2014-12-12 09:19:05
【问题描述】:
我想知道当您使用 Eloquent 的 with 方法检索关系时是否可以为表提供别名?
例如:
Post::where('title', 'like', '%' . $title . '%')
->where('published', 1)
->with(['medias AS jpeg' => function($q) {
$q->where('format', 'jpeg');
}])->with(['medias AS gif' => function($q) {
$q->where('format', 'gif');
}])->first();
我知道这行不通,但这是为了给你一个情况。
有可能还是我必须手动操作?
提前谢谢你。
【问题讨论】: