1
如果得到了以下数据库表: Laravel雄辩其中功能不起作用
现在我想显示哪里哪里“inventory_warning”是更大的,则“清单”字段的行。像第二个结果,如下所示:
在我的第一个例子,我做一个WHERE语句用雄辩的,并得到了行,但它不会产生正确的结果(它会检索所有行)。我的第二个例子显示了一个PHP-if语句做了检查,这工作,但会当表中包含更多的数据非常低效..
缩短代码:
<?php $products = Product::where('inventory_warning', '>', 'inventory')->get();?>
<tr>
<th colspan="3">First results:</th>
</tr>
@foreach($products as $product)
<tr>
<td># {{ $product->id }} - {{$product->item->name}}</td>
<td>{{ $product->inventory }}</td>
<td>{{ $product->inventory_warning }}</td>
</tr>
@endforeach
<?php $products = Product::all();?>
<tr>
<th colspan="3">Second results:</th>
</tr>
@foreach($products as $product)
@if($product->inventory_warning > $product->inventory)
<tr>
<td># {{ $product->id }} - {{$product->item->name}}</td>
<td>{{ $product->inventory }}</td>
<td>{{ $product->inventory_warning }}</td>
</tr>
@endif
@endforeach
这到底是怎么回事?这是一个可能的雄辩错误还是我做错了什么?
是的,谢谢!这似乎起作用了,快速浏览Eloquent的来源,证实where函数确实不支持字段比较。 (本来可以期望的).. 函数声明: public function where($ column,$ operator = null,$ value = null,$ boolean ='and') – EvdTempel 2014-11-01 11:22:38