【发布时间】:2019-11-02 21:57:00
【问题描述】:
我想使用 Laravel Eloquent 结构编写查询。我想在输入最小值和最大值后查询这些值。我有一个产品表。带有折扣 (%) 和价格的列产品表。我想根据产品的折扣值获得最小值和最大值。
我希望这是基于包括折扣在内的查询。
$products->where('price', '<=', $max)
->where('price', '>=', $min)
->orderByDesc('id')
->paginate(9);
产品迁移:
Schema::create('products', function (Blueprint $table) {
$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('discount');
$table->timestamps();
});
非常感谢您。
【问题讨论】:
-
如果您只是要求 Eloquent,那么您可以针对您的问题编写 SQL 查询,然后我们可以帮助将其转换为 Eloquent。