我有一个表单,其中有一个字段被禁用,并且包含从类函数收集的动态值,代码如下:
{!! Form::input('number', 'estimate', Estimate::getTotal($userId), ['class' => 'form-control', 'disabled']) !!}
现在我想完成的是在它后面添加一个静态货币字符串,比如"USD"。所以文本字段将包含"5000 USD",而不仅仅是数字。我该怎么做?
哦,功能看起来是这样的:
public static function getTotal($userId)
{
$estimates = self::whereNull('case_id')->where('user_id', '=', $userId)->get();
$total = 0;
foreach ($estimates as $estimate){
$rate = Competence::where('id', $estimate->competence_id)->first()->hourely_rate;
$total = $total + $estimate->hours * $rate;
}
return $total;
}
您使用的是number
输入类型,这很好地解释了该输入不能包含字符串。将类型更改为text
并简单使用:
Estimate::getTotal($userId) . ' USD'
您也可以编辑您的函数以返回总金额加上货币。