简体   繁体   中英

getting an error in where laravel eloquent

I have on input as amount and also getting the discount price but getting an error in where condition,

Here is my query,

public function getDiscountProducts(Request $request){

        $amount = $request->input('amount');

        $products = DB::table('products')
        ->select(DB::raw('(((mrp - price) * 100) / mrp) AS discount'))
        ->where(DB::raw('(((mrp - price) * 100) / mrp) AS discount'), $amount)
        ->get();

   
        return response()->json([
            'message' => 'All categories Products',
            'code' => 200,
            'data' => $products,
            'status' => 'success'
        ]);
    }

Please check where I am missing,

Error:

"Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AS discount is null' at line 1 (SQL: select (((mrp - price) * 100) / mrp) AS discount from products where (((mrp - price) * 100) / mrp) AS discount is null)"

尝试从 where 条件中删除AS discount

try changing this line

->where(DB::raw('(((mrp - price) * 100) / mrp) AS discount'), $amount)

to

->where(DB::raw('(((mrp - price) * 100) / mrp)'), $amount)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM