Laravel 4.2 Eloquent: 我如何 return 基于以下查询的 id 计数?
Laravel 4.2 Eloquent: How can i return the count of id based on the following query?
这是我的 eloquent 模型。
public function getRecordCount($id = NULL){
if ($id == 0) {
$count = $this->leftJoin('liip_user_customers', 'warehouse_to', '=', 'liip_user_customers.customer_id')
->where('status', '=', $id)
->where('created_by_id', '=', Auth::user()->id)
->select('id')
->count('id');
if (!empty($count)) {
return $count;
}else{
return 0;
}
}
}
这是我的控制器。
public function getIndex(){
$count_approval = $this->warehouse_transfer->getRecordCount(0);
$count_correction = $this->warehouse_transfer->getRecordCount(14);
$count_final = $this->warehouse_transfer->getRecordCount(13);
$count_pending = $this->warehouse_transfer->getRecordCount(15);
// Title
$title = Lang::get('liipWarehousePalletTransfer::warehousePalletTransfer/title.warehouse_pallet_transfers_management');
// Show the page
return View::make('liipWarehousePalletTransfer::index', compact( 'title', 'count_approval', 'count_correction', 'count_close', 'count_disapprove', 'count_final', 'count_pending'));
}
我遇到了一些错误:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id'
in field list is ambiguous (SQL: select count(`id`) as aggregate from
`liip_warehouse_pallet_transfers` left join `liip_user_customers` on
`warehouse_to` = `liip_user_customers`.`customer_id` where `status` = 0
and `created_by_id` = 159)
Check the attached image
"For Approval" 选项卡中的徽章应为“5”。
我已经搜索过这个问题,但找不到与我相同的情况。
$this->leftJoin('liip_user_customers',
'warehouse_to', '=', 'liip_user_customers.customer_id')
发生错误是因为您在左联接中缺少 table 名称 TABLE_NAME.warehouse_to
有关详细信息,请参阅 Laravel Join
这是我的 eloquent 模型。
public function getRecordCount($id = NULL){
if ($id == 0) {
$count = $this->leftJoin('liip_user_customers', 'warehouse_to', '=', 'liip_user_customers.customer_id')
->where('status', '=', $id)
->where('created_by_id', '=', Auth::user()->id)
->select('id')
->count('id');
if (!empty($count)) {
return $count;
}else{
return 0;
}
}
}
这是我的控制器。
public function getIndex(){
$count_approval = $this->warehouse_transfer->getRecordCount(0);
$count_correction = $this->warehouse_transfer->getRecordCount(14);
$count_final = $this->warehouse_transfer->getRecordCount(13);
$count_pending = $this->warehouse_transfer->getRecordCount(15);
// Title
$title = Lang::get('liipWarehousePalletTransfer::warehousePalletTransfer/title.warehouse_pallet_transfers_management');
// Show the page
return View::make('liipWarehousePalletTransfer::index', compact( 'title', 'count_approval', 'count_correction', 'count_close', 'count_disapprove', 'count_final', 'count_pending'));
}
我遇到了一些错误:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id'
in field list is ambiguous (SQL: select count(`id`) as aggregate from
`liip_warehouse_pallet_transfers` left join `liip_user_customers` on
`warehouse_to` = `liip_user_customers`.`customer_id` where `status` = 0
and `created_by_id` = 159)
Check the attached image
"For Approval" 选项卡中的徽章应为“5”。 我已经搜索过这个问题,但找不到与我相同的情况。
$this->leftJoin('liip_user_customers',
'warehouse_to', '=', 'liip_user_customers.customer_id')
发生错误是因为您在左联接中缺少 table 名称 TABLE_NAME.warehouse_to
有关详细信息,请参阅 Laravel Join