I have 2 forms for editing and inserting in my project and I am using form model binding.
During insertion, there is a field that is required called code
. This code is associated with the image
of the product. So I want that I during the editing, the code
field should become readOnly
?
How do I achieve this ?
insertion:
{!! Form::open(['url' => '/admin/products', 'autocomplete' => 'off', 'id' => 'formAddProduct', 'files' => true, 'name' => 'formAddProduct']) !!}
<div class="errors"></div>
@include('admin.products.form', ['submitButtonText' => 'Add Product', 'submitButtonId' => 'btnAddProduct'])
{!! Form::close() !!}
editing:
{!! Form::model($product, ['method' => 'PATCH', 'action' => ['AdminProductsController@update', $product->id], 'autocomplete' => 'off', 'id' => 'formEditProduct', 'files' => true]) !!}
<div class="errors"></div>
@include('admin.products.form', ['submitButtonText' => 'Edit Product', 'submitButtonId' => 'btnEditProduct'])
{!! Form::close() !!}
form.blade.php:
<div class="form-group">
{!! Form::label('code', 'Code') !!}
{!! Form::text('code', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('category_id', 'Category:') !!}
{!! Form::select('category_id', $categories, null, ['class' => 'form-control']) !!}
</div>