1

I am trying to add a PHP variable to an input type number, as the maximum value allowed in this field. I am using Laravel collective.

My input syntax:

{!! Form::number('credit_amount', '0.00', ['step' => '0.01', 'min' => '0.01', 'max' => '{{ $creditBalance }}', 'class' => 'text-center form-control']) !!}

I want the $creditBalance placed against the "max" attribute of the number input. I can do this without Laravel Collective, but how to do it with LC? Thanks!

TheRealPapa
  • 4,393
  • 8
  • 71
  • 155
  • You should remove '{{ and }}' from the max attribute, as this is parsed in plain PHP, not a blade-powered value. – Jan Willem Sep 15 '16 at 08:51

1 Answers1

4

Blade essentially just replaces {!! and !!} with <?php echo and ?> respectively, so you can use normal PHP code:

{!! Form::number('credit_amount', '0.00', ['min' => '0.01', 'max' => $creditBalance, 'class' => 'text-center form-control']) !!}
Thomas
  • 8,426
  • 1
  • 25
  • 49
  • Hi @Thomas, this resolves OK, but the input field now does not span 100% width per its CSS. Without this parameter & its PHP var, input spans 100% of container width. Why do you think? – TheRealPapa Sep 15 '16 at 08:55
  • Your CSS seems to be wrongly applied or is being overwritten. Try the browser dev tools. – Thomas Sep 15 '16 at 08:58
  • checked but it looks ok. I am using default Bootstrap CSS. Interestingly, if I write the HTML directly with the PHP var is the same result, screws CSS. I take the MAX attribute out, and it all shows up perfectly. – TheRealPapa Sep 15 '16 at 09:24
  • I changed `step = "0.01"` to `step = "any"` and it works now – TheRealPapa Sep 15 '16 at 09:45