Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel form echo variable

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.

like image 429
hatemjapo Avatar asked Nov 21 '25 09:11

hatemjapo


1 Answers

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']) !!}
like image 140
Alexey Mezenin Avatar answered Nov 23 '25 23:11

Alexey Mezenin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!