简体   繁体   English

laravel表单文本,带有值扩展

[英]laravel form text with value extension

I have a form where there's a field that is disabled and contains a dynamic value gathered from a class function, code looks like this: 我有一个表单,其中有一个字段被禁用,并且包含从类函数中收集的动态值,代码如下所示:

{!! Form::input('number', 'estimate', Estimate::getTotal($userId), ['class' => 'form-control', 'disabled']) !!}

Now what I want to accomplish is to add a static currency string, like 'USD', after it. 现在,我要完成的工作是在其后添加一个静态货币字符串,例如“ USD”。 So the textfield would contain "5000 USD", instead of the just the number. 因此,文本字段将包含“ 5000 USD”,而不仅仅是数字。 How can I do that? 我怎样才能做到这一点?

Oh and the function looks like this: 哦,函数看起来像这样:

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;
}

You're using an number input type, pretty self explaining that this input can't contain a string. 您使用的是number输入类型,很容易说明该输入不能包含字符串。 Change the type to text and simply use: 将类型更改为text ,只需使用:

Estimate::getTotal($userId) . ' USD'

You could also edit your function to return the total amount plus the currency. 您还可以编辑函数以返回总额加货币。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM