亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

帶有ajax響應的laravel

帶有ajax響應的laravel

PHP
撒科打諢 2022-07-22 19:03:52
我的應用程序返回錯誤,我需要知道原因。我提出了一個 AJAX 請求,以獲取他在熱賣或特價商品中選擇的所有產品,并且...如果我刪除此查詢功能,它會返回數據。如何將此請求選中框傳遞給此函數?函數 App\Http\Controllers\Website\AllProductController::App\Http\Controllers\Website\{closure}() 的參數太少,1 傳入 /...../vendor/laravel/framework/src/Illuminate /Database/Eloquent/Builder.php 在第 226 行,預計正好 2public function ajax_category(Request $request)    {        if(isset($request->price) && isset($request->categories_id))        {        $product_category = $request->categories_id;        // change the value from string to array.        if (isset($request->selectedbox) && $request->selectedbox !='') {            $pairs = $request->selectedbox;            $newArray = explode(",", $pairs);        }        if (!empty($request->categories_id)) {            $max = $request->max;            $min = $request->min;        } else {            $min = product_model::where('pactive', 1)->select('MIN("price")')->first();            $max = product_model::where('pactive', 1)->select('MAx("price")')->first();        }        // change the value from string to array.        if (!empty($request->priceRange)) {            $currentRange = $request->priceRange;            $priceArray = explode(",", $currentRange);            $firstPrice = $priceArray[0];            $secondPrice = $priceArray[1];        } else {            $firstPrice = $min;            $secondPrice = $max;        }        $products = product_model::where('category', $request->categories_id)            ->whereBetween('price', [$firstPrice, $secondPrice]);        if (isset($request->selectedbox) && $request->selectedbox !='') {            $products = $products->where(function ($query,Request $request) {                $pairs = $request->selectedbox;                $newArray = explode(",", $pairs);                $query->whereIn('poffertype',implode(',', $newArray))                    ->orwhereIn('brand', implode(',', $newArray))                    ->orwhereIn('brand_ar', implode(',', $newArray));            });        }
查看完整描述

1 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

這部分:

$products = $products->where(function ($query,Request $request) {

應該

$products = $products->where(function ($query) use ($request) {

use關鍵字可用于多種用途,其中之一是繼承閉包中的變量。


查看完整回答
反對 回復 2022-07-22
  • 1 回答
  • 0 關注
  • 136 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號