DEV Community

Sospeter Mong'are
Sospeter Mong'are

Posted on

Display dropdown in blade in laravel

<div class="form-group">
<label for="category_id">Transaction category</label>
<select class="form-control" id="category_id" name="category_id" required>
@foreach($categories as $category)
<option value="{{ $category->id }}" {{ $transaction->category_id == $category->id ? 'selected' : '' }}>
{{ $category->name }}
</option>
@endforeach
</select>
</div>

Top comments (1)

Collapse
 
limon96 profile image
Limon96

You can do it like this:

<option value="{{ $category->id }}" @selected($transaction->category_id == $category->id)>
{{ $category->name }}
</option>
Enter fullscreen mode Exit fullscreen mode