'Invalid parameter number in Laravel Raw Query
I have the following query in mysql
select count(*) as aggregate from `promotions` where `supplier_id` = 1 and '2022-03-27' <= promotions.to AND '2022-04-27' >= promotions.from
is is working fine from Mysql workbench how to achieve this same code from Laravel raw query i have tried this gives me an error SQLSTATE[HY093]: Invalid parameter number
$validate = DB::table('promotions')
->where('supplier_id',$supplier_id)
->whereRaw("'?' <= promotions.to AND '?' >= promotions.from",[$request->post('from'),$request->post('to')])
->count();
Full error was shows like this
"SQLSTATE[HY093]: Invalid parameter number (SQL: select count(*) as aggregate from
promotions
wheresupplier_id
= 1 and '2022-03-27' <= promotions.to AND '2022-04-27' >= promotions.from)"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|