第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

當(dāng)數(shù)據(jù)庫中有 1 條記錄時(shí),Laravel 顯示重復(fù)項(xiàng)

當(dāng)數(shù)據(jù)庫中有 1 條記錄時(shí),Laravel 顯示重復(fù)項(xiàng)

PHP
犯罪嫌疑人X 2023-07-30 13:54:55
我是 Laravel 的初學(xué)者。我在使用 Laravel 時(shí)遇到了一些小問題。我有這個(gè)代碼:$categories = $categoryRepository->descendantsAndSelf($slug ?? null); 這個(gè)返回:Illuminate\Support\Collection {#535 ▼  #items: array:17 [▼    0 => 1    1 => 2    2 => 3    3 => 4    4 => 5    5 => 6    6 => 7    7 => 8    8 => 9    9 => 10    10 => 11    11 => 12    12 => 13    13 => 14    14 => 15    15 => 16    16 => 17  ]}還有我的存儲(chǔ)庫:public function getProductFromIdCategories($categories)    {        return $this->model->select('name', 'slug', 'products.id', 'small_description')->with(['selectedCategory', 'frontImage'])->active()->leftJoin('selected_product_categories', function ($join) {            $join->on('products.id', 'selected_product_categories.product_id');        })->whereIn('selected_product_categories.category_id', $categories)->get();      }當(dāng)我運(yùn)行我的代碼時(shí):dd($this->model->getProductFromIdCategories($categories->toArray()));
查看完整描述

1 回答

?
當(dāng)年話下

TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊

您有關(guān)系“selectedCategory”。那么為什么要使用左連接呢?使用此代碼


public function getProductFromIdCategories($categories)

{

    return $this->model->select('name', 'slug', 'products.id', 'small_description')

    ->with(['selectedCategory', 'frontImage', 'selectedCategory' => function($q) use ($categories){

        $q->whereIn('category_id', $categories);

    }])->active()->get();  

}


查看完整回答
反對(duì) 回復(fù) 2023-07-30
  • 1 回答
  • 0 關(guān)注
  • 143 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)