Php 拉维伯爵酒店
我需要用withcount计算订单乘客Php 拉维伯爵酒店,php,laravel,Php,Laravel,我需要用withcount计算订单乘客 $orders = $this->orderRepository ->search($filters, true) ->sort($sort) ->select([ 'id', 'code', 'pro_periods_id',
$orders = $this->orderRepository
->search($filters, true)
->sort($sort)
->select([
'id',
'code',
'pro_periods_id',
'quantity_adult_single',
'quantity_adult_double',
'quantity_adult_triple',
'quantity_child_bed',
'quantity_child_no_bed',
'quantity_infant',
'created_at',
'created_by'
])
->with(['orderPassengers' => function($sub_query){
$sub_query->select([
'id',
'pro_orders_id',
'pro_rooms_id',
'title_name',
'first_name_en',
'last_name_en',
'birth_date'
])
->with(['room' => function($sub_query){
$sub_query->select([
'id',
'pro_periods_id',
'room_number',
'room_type',
'extra_bed'
]);
}]);
}])
->withCount('orderPassengers');
这是我的结果
我对伯爵一窍不通
如何获取订单乘客数量。试试以下方法:
$orders = $this->orderRepository
->search($filters, true)
->sort($sort)
->select([
'id',
'code',
'pro_periods_id',
'quantity_adult_single',
'quantity_adult_double',
'quantity_adult_triple',
'quantity_child_bed',
'quantity_child_no_bed',
'quantity_infant',
'created_at',
'created_by'
])
->withCount(['orderPassengers' => function($sub_query){
$sub_query->select([
'id',
'pro_orders_id',
'pro_rooms_id',
'title_name',
'first_name_en',
'last_name_en',
'birth_date'
])
->with(['room' => function($sub_query){
$sub_query->select([
'id',
'pro_periods_id',
'room_number',
'room_type',
'extra_bed'
]);
}]);
}]);
你应该试试这个:
$orders = $this->orderRepository
->search($filters, true)
->sort($sort)
->select([
'id',
'code',
'pro_periods_id',
'quantity_adult_single',
'quantity_adult_double',
'quantity_adult_triple',
'quantity_child_bed',
'quantity_child_no_bed',
'quantity_infant',
'created_at',
'created_by'
])
->withCount(['orderPassengers' => function($sub_query){
$sub_query->select([
'id',
'pro_orders_id',
'pro_rooms_id',
'title_name',
'first_name_en',
'last_name_en',
'birth_date'
])
->with(['room' => function($sub_query){
$sub_query->select([
'id',
'pro_periods_id',
'room_number',
'room_type',
'extra_bed'
]);
}]);
}])->get();
只能对模型的已定义关系执行
withCount()
class Order extends Model
{
function orderPassengers()
{
return $this->hasMany('App\orderPassengers');
}
}
如何执行查询?有了
->get()
?我什么都没有准备好。