Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel雄辩的构建查询_Php_Laravel_Eloquent - Fatal编程技术网

Php Laravel雄辩的构建查询

Php Laravel雄辩的构建查询,php,laravel,eloquent,Php,Laravel,Eloquent,我想使用Laravel雄辩的结构编写一个查询。我想查询这些值​​输入最小值和最大值后。我有一张产品表。列产品表,包括折扣(%)和价格。我想根据产品的折扣值得到最小值和最大值 我希望这是基于包括折扣的查询 $products->where('price','=',$min) ->orderByDesc('id') ->分页(9); 产品迁移: Schema::创建('products',函数(Blueprint$表){ $table->bigIncrements('id'); $table->u

我想使用Laravel雄辩的结构编写一个查询。我想查询这些值​​输入最小值和最大值后。我有一张产品表。列产品表,包括折扣(%)和价格。我想根据产品的折扣值得到最小值和最大值

我希望这是基于包括折扣的查询

$products->where('price','=',$min)
->orderByDesc('id')
->分页(9);
产品迁移:

Schema::创建('products',函数(Blueprint$表){
$table->bigIncrements('id');
$table->unsignedBigInteger('upper_category_id')->index();
$table->unsignedBigInteger('category_id')->index();
$table->unsignedBigInteger('user_id')->index();
$table->string('name');
$table->longText('text');
$table->float('price')->index();
$table->integer('stock');
$table->float(‘折扣’);
$table->timestamps();
});

事先非常感谢。

如果我正确理解了您的问题,您可以这样做:

$products->where(DB::raw('price-price*discount'),'=',$min)
->orderByDesc('id')
->分页(9);

如果您只是要求Eloquent,那么您可以为您的问题编写SQL查询,然后我们可以帮助将其转换为Eloquent。