laravel表单文本的值扩展名

时间:2014-11-12 10:07:14

标签: php forms laravel

我有一个表单,其中有一个禁用的字段并包含从类函数收集的动态值,代码如下所示:

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

现在我想要完成的是在它之后添加一个静态货币字符串,如'USD'。因此,textfield将包含“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;
}

1 个答案:

答案 0 :(得分:1)

您正在使用number输入类型,非常自我解释此输入不能包含字符串。将类型更改为text,只需使用:

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

您还可以编辑您的功能以返回总金额加上货币。