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

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

laravel 相當(dāng)于隨機(jī)排序

laravel 相當(dāng)于隨機(jī)排序

我是 Laravel 的初學(xué)者。我在 Laravel 7 中有一個(gè)項(xiàng)目。我有這個(gè)代碼:public function getPromoProducts()    {        return $this->model->select('name', 'slug', 'products.id', 'small_description', 'promo_desc')->with(['features', 'frontImage'])->active()->leftJoin('selected_product_features', function ($join) {            $join->on('products.id', '=', 'selected_product_features.product_id');        })->where('selected_product_features.key', 'price_promo')->where('selected_product_features.description', '<>', 0)->limit(2)->get();    }我怎樣才能從傳統(tǒng)的mysql添加到這個(gè)代碼“ORDER BY RAND()”?請(qǐng)幫我
查看完整描述

1 回答

?
郎朗坤

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

Laravel 有inRandomOrder()方法,在查詢(xún)生成器上調(diào)用它。在引擎蓋下,它將使用以下內(nèi)容進(jìn)行訂購(gòu)。

return?$this->model->select('name',?'slug',?'products.id',?'small_description',?'promo_desc')
????->with(['features',?'frontImage'])
????->active()
????->leftJoin('selected_product_features',?function?($join)?{?
???????????$join->on('products.id',?'=',?'selected_product_features.product_id');
????})->where('selected_product_features.key',?'price_promo')
????->where('selected_product_features.description',?'<>',?0)
????->limit(2)
????->inRandomOrder()
????->get();


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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