[英]Laravel Eloquent Inner Join
This is the query I currently using for Inner Join
in my laravel app: 这是我当前在laravel应用中用于
Inner Join
的查询:
public function getReservationListAPI()
{
$id = JWTAuth::parseToken()->authenticate()->id;
$result = DB::table('pporders AS ord')
->join('products AS pd', 'ord.product_id', '=', 'pd.id')
->select('ord.*')
->where('pd.user_id',$id)
->get();
dd($result);
}
How can I wrote this query in Eloquent form? 如何以口才的形式编写此查询? Thanks!!
谢谢!!
Relationship: 关系:
Product hasMany Order
Order belongsTo Product
User hasMany Product
Product belongsTo User
It depends on your relation, but something like this: 这取决于您的关系,但是像这样:
Pporders::with(['product' => function($q) use($id) {
$q->where('user_id', $id);
}])->get();
But it won't make the same sql query what you described, but gives the same result. 但这不会使您描述的SQL查询相同,但是会得到相同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.