【问题标题】:How to use Laravel Directive Currency format in Blade with laravel Collective如何通过 laravel Collective 在 Blade 中使用 Laravel 指令货币格式
【发布时间】:2021-08-15 06:03:50
【问题描述】:

我有一些这样的文本框 {{{ Form::number('amount', $cash->amount , array('class'=>'form-control')) }}} 但我想以货币格式显示文本框

我尝试过像这样制作 Laravel 指令 Blade::directive('convert', function ($money) { return "<?php echo 'Rp.' . number_format($money, 2); ?>"; });

当我在文本框{{{ Form::number('amount', @convert($cash-&gt;amount) , array('class'=&gt;'form-control')) }}} 中尝试返回解析错误时,意外'<label>@convert(11223344)</label> 这是工作。

谢谢

【问题讨论】:

    标签: laravel laravel-blade laravelcollective


    【解决方案1】:

    我认为这是你需要的:

    {{{ Form::number('amount', 'Rp.' . number_format($cash->amount, 2), array('class'=>'form-control')) }}}
    

    【讨论】:

    • aw,这不是错误,但值未显示。在控制台中我看到警告The specified value "1,000,000.00" cannot be parsed, or is out of range.
    • 首先,你能不能把上面代码中的'Rp.' .去掉再试一次。我忘了这是一个数字输入类型。
    • 我已经删除了 Rp。 ,但同样的错误。
    猜你喜欢
    • 2015-10-24
    • 2018-04-01
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 2021-03-31
    • 2019-11-19
    相关资源
    最近更新 更多