- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to make Laravel (Blade) text field read-only?
Blade is a template engine that helps you to build your view display in laravel. It also helps you to use php code inside the template.
The blade templates are saved as filename.blade.php and are stored inside resources/views/ folder. To understand the above question let us create a view calling the blade template.
Example 1
Inside routes/web.php I have created the following route that is calling the view hello with data ['mymsg' => 'Welcome to Tutorialspoint'].
Route::get('hello', function () { return view('hello', ['mymsg' => 'Welcome to Tutorialspoint']); });
The hello.blade.php is inside resources/views folder −
{{$mymsg}}
Output
The output when you test will be −
Welcome to Tutorialspoint
Example 2
Adding text field inside blade template
Now let us understand how to add text field and make it readonly.
<?php echo Form::open(array('url'=>'/hello')); echo Form::text('name'); echo Form::close(); ?>
Output
Now if you check, you will see a textbox as shown in the output −
Example 3
To make a text field as read-only you need to add the following code −
<?php echo Form::text('name',null, ['readonly']); ?>
The code inside hello.blade.php is as follows −
<?php echo Form::open(array('url'=>'/hello')); echo Form::text('name',null, ['readonly']); echo Form::close(); ?>
Output
Now when you check the output it will be as follows −
Example 4
you can also add the html input text with read-only attribute in blade template as shown below −
<?php echo Form::open(array('url'=>'/hello')); echo Form::text('name',null, ['readonly']); echo Form::close(); ?> <input readonly="readonly" name="username" type="text" value="readonly">
Output
The output of the above code is as follows −