DEV Community

Sospeter Mong'are
Sospeter Mong'are

Posted on

2

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

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

πŸ‘₯ Ideal for solo developers, teams, and cross-company projects

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay