Laravel关联查询时,如何让字段自带表前缀?
例子中的关联查询,别管用不用得到关联 users 表,我都得在所有字段面前加上 orders.,请问有没有什么办法能省去 orders.
$query = Order:query()
//根据支付状态查询
if ($request->is_pay) {
$query->where('orders.is_pay', $request->is_pay);
}
//根据用户手机号查询
if ($request->user_mobile) {
$query->leftJoin('users', 'users.id', '=', 'orders.user_id')
->where('users.mobile', $request->user_mobile);
}
推荐文章: