How to make Laravel (Blade) text field readonly

52,187

Solution 1

Just add it as the 3rd argument:

{{ Form::text('login_token', Worker::generateLoginToken(), ['readonly']) }}

Solution 2

That's how I did it in Laravel 5:

{!! Form::text('id', null, ['class' => 'form-control', 'readonly' => 'true']) !!}

Cheers.

Solution 3

Write the following line

{!! Form::text('field_name','field_value',array('class'=>'form-control','readonly')) !!}

Solution 4

For Laravel 5 and above

{!! Form::text('name', 'default-value', ['class'=>'class-name','readonly']) !!}

In third argument you can pass all your extra arguments in form of an array. This line will result into something like this in html.

<input class="class-name" readonly="readonly" name="name" type="text" value="default-value">

For Laravel < 5 , this should work

{{ Form::text('name', 'default-value', ['class'=>'class-name','readonly']) }}
Share:
52,187

Related videos on Youtube

Marcel Gruber
Author by

Marcel Gruber

C#.NET VB.NET Sitecore SEO PHP / Laravel Knockout.JS Objective C Owner of Luxica Consulting Corp.

Updated on March 14, 2020

Comments

  • Marcel Gruber
    Marcel Gruber about 4 years

    I have a text box that needs to be made readonly; I don't want to use array('disabled' => 'true') because I need PHP to process the field:

    {{ Form::text('login_token', Worker::generateLoginToken()) }}
    

    How do you add this attribute?

  • Lea Cohen
    Lea Cohen about 9 years
    If you could please explain what the code you're showing does, and why/how that code answers the question, it would make your answer even more helpful.
  • Marcel Gruber
    Marcel Gruber about 9 years
    Both this and the answer by @Jocker produce the same results. Both work. Thanks!