简体   繁体   English

其中 laravel 不能使用变量

[英]wherebetween laravel not working with variable

I am using Laravel 5.8, and I would like to get rows between two prices in my database.我正在使用 Laravel 5.8,我想在我的数据库中获取两个价格之间的行。

I using this code to get my product:我使用此代码来获取我的产品:

$prd = Product::where($args)->whereBetween('price', [$request->min_price, $request->max_price])->get();

But the problem is when I use the code above and I return $prd;但问题是当我使用上面的代码并return $prd; nothing returned but when I put a static number as $request->min_price or $request->max_price it works correctly没有返回,但是当我将 static 数字作为$request->min_price$request->max_price时,它可以正常工作

I must set one of them as a static number like this:我必须将其中一个设置为 static 编号,如下所示:

$prd = Product::where($args)->whereBetween('price', [100, $request->max_price])->get();

or:或者:

$prd = Product::where($args)->whereBetween('price', [$request->min_price, 1000])->get();

Where is my problem or mistake?我的问题或错误在哪里?

have you tried to typecast them with integer, maybe they are numeric,您是否尝试过使用 integer 对它们进行类型转换,也许它们是数字的,

$prd = Product::where($args)->whereBetween('price', [(int)($request->min_price), (int)($request->max_price)])->get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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