How to change value change text in laravel?

by raven_corwin , in category: PHP Frameworks , 4 months ago

How to change value change text in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by gilbert , 4 months ago

@raven_corwin 

To change the value of a text input field in Laravel, you can use the old() function in your blade file within the value attribute of the input field. Here's an example:

1
<input type="text" name="username" value="{{ old('username') }}">


This code will populate the input field with the value of the 'username' input that was submitted in a previous form submission. If no value was submitted for 'username', the input field will remain empty.


You can also manually set the value of the input field in your controller before rendering the view. Here's an example:

1
2
$username = 'john_doe';
return view('my-view', ['username' => $username]);


And in your blade file, you can set the value of the input field like this:

1
<input type="text" name="username" value="{{ $username }}">


This will set the value of the input field to 'john_doe' when the view is rendered.