Skip links

What is the best practice to show old value when editing a form in Laravel?

On Create/POST Pages

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

<textarea>{{old('notes')}}</textarea>

<div class="form-group">    
    <label for="category">Product</label>
    <select name="category_id" id="category_id" class="form-control">
        @foreach($category as $item)
    <option value="{{$item->id}}"
        @if($item->id == old('category_id'))
        selected
        @endif
                >{{$item->title}}</option>
                @endforeach
    </select>
</div>

On Update Pages

<input type="text" value="{{old('name', $client->name)}}">

<textarea>{{old('notes', $client->description)}}</textarea>

Leave a comment