如何计算Laravel刀片产品的总价格
我想计算一下总价。我怎么做 这是我的刀片代码:如何计算Laravel刀片产品的总价格,laravel,laravel-blade,Laravel,Laravel Blade,我想计算一下总价。我怎么做 这是我的刀片代码: @foreach ($ventes as $value) <td>{{ $value->produit->nom }}</td> <td> {{ $value->quantitevendu }}</a> </td> <t
@foreach ($ventes as $value)
<td>{{ $value->produit->nom }}</td>
<td>
{{ $value->quantitevendu }}</a>
</td>
<td>
({{$value->prix}})*{{$value->quantitevendu}}.euro
</td>
<td>
({{$value->prix}}).DH
</td>
<td>
{{ $value->description }}
</td>
</tr>
@endforeach
@foreach($ventes as$value)
{{$value->produit->nom}
{{$value->quantitevendu}
({{$value->prix}})*{{$value->quantitevendu}.euro
({{$value->prix}).DH
{{$value->description}
@endforeach
它给我这样的结果:
(10) *2
(11) *4
(2) *1
但我想要这样的结果:
二十
44
2您执行的是串联而不是乘法。试试这个:
@foreach ($ventes as $value)
<td>{{ $value->produit->nom }}</td>
<td>
{{ $value->quantitevendu }}</a>
</td>
<td>{{$value->prix * $value->quantitevendu}} .euro</td>
<td>({{$value->prix}}).DH</td>
<td>{{ $value->description }}</td>
</tr>
@endforeach
@foreach($ventes as$value)
{{$value->produit->nom}
{{$value->quantitevendu}
{{$value->prix*$value->quantitevendu}.euro
({{$value->prix}).DH
{{$value->description}
@endforeach
我希望你明白了。你做的是串联而不是乘法。试试这个:
@foreach ($ventes as $value)
<td>{{ $value->produit->nom }}</td>
<td>
{{ $value->quantitevendu }}</a>
</td>
<td>{{$value->prix * $value->quantitevendu}} .euro</td>
<td>({{$value->prix}}).DH</td>
<td>{{ $value->description }}</td>
</tr>
@endforeach
@foreach($ventes as$value)
{{$value->produit->nom}
{{$value->quantitevendu}
{{$value->prix*$value->quantitevendu}.euro
({{$value->prix}).DH
{{$value->description}
@endforeach
我希望你能明白。你的计算应该用大括号括起来
<td>{{ ($value->prix * $value->quantitevendu) }}.euro</td>
{{($value->prix*$value->quantitevendu)}.euro
您的计算应该用大括号括起来
<td>{{ ($value->prix * $value->quantitevendu) }}.euro</td>
{{($value->prix*$value->quantitevendu)}.euro
在模型中进行大量计算是最佳做法。Laravel允许在虚拟属性不存在时创建虚拟属性事件
在你的桌子上。为此,您可以定义一个属性访问器,在其中执行所有计算,如下面所示
class Vente extends Model {
public function getPrixTotalAttribute()
{
return $this->attributes['prix'] * $this->attributes['quantitevendu'];
}
}
在你看来,你只需做
{{$value->prix_total}
在你的模型中进行大量计算是最好的做法。Laravel允许在虚拟属性不存在时创建虚拟属性事件
在你的桌子上。为此,您可以定义一个属性访问器,在其中执行所有计算,如下面所示
class Vente extends Model {
public function getPrixTotalAttribute()
{
return $this->attributes['prix'] * $this->attributes['quantitevendu'];
}
}
在你看来,你只需要做
{{$value->prix_total}
它不需要用大括号括起来。大括号仅强制运算符的优先级。在本例中,无论是否使用大括号,结果都是相似的。您将大括号误认为是大括号。在这种情况下,括号是可选的,但需要大括号来显示值,不需要用大括号括起来。大括号仅强制运算符的优先级。在本例中,无论是否使用大括号,结果都是相似的。您将大括号误认为是大括号。在这种情况下,括号是可选的,但需要大括号来显示值。非常欢迎。我希望你在享受拉腊维莱,非常欢迎你。我希望你喜欢拉维拉格里德。您应该在模型中计算总计,而不是视图。同意。您应该在模型中计算总计,而不是在视图中。