簡體   English   中英

Laravel 4.2 Eloquent:如何根據以下查詢返回id的數量?

[英]Laravel 4.2 Eloquent: How can i return the count of id based on the following query?

這是我雄辯的榜樣。

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)

檢查附件圖片

“待批准”標簽中的徽章應為“ 5”。 我已經搜索過這個問題,但是找不到像我一樣的情況。

$this->leftJoin('liip_user_customers', 
        'warehouse_to', '=', 'liip_user_customers.customer_id')

發生錯誤是因為您缺少左TABLE_NAME.warehouse_to的表名。

有關更多信息,請參見Laravel Join

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM