i am still learning how to work with laravel. Now i have learned how to make a form in laravel. But i have some trouble to echo a variable. What i want to do is: i want to echo a variable as the value of an input-field if this variable exists, otherwise it should echo nothing. so my form line looks like this
{{Form::text(
'league_name',
'@if(isset($varialble) {{$variable}} @else {{$nothing}} @endif)'
)}}
How can i echo a variable in a form?
i am using blade btw.
This is the right way to do it:
{!! Form::text('league_name', isset($varialble) ? $variable : '') !!}
If you're using PHP7, you can do this:
{!! Form::text('league_name', $varialble) ?? '') !!}
Update
To add placeholder, pass it in an array as third parameter. Also, you usually want to pass a class:
{!! Form::text('league_name', isset($varialble) ? $variable : '', ['placeholder' => 'My placeholder', 'class' => 'form-control']) !!}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With