Skip to main content
Quick Tip

Selected blade directive

In Laravel 9+, you'll be able to use the cool new "selected" Blade directive for HTML select elements.

This is going to be a nice addition that we can use to clean up our Blade views a little bit

// Before Laravel 9:
<select name="country">
<option value="India" {{ old('country') ?? $country == 'India' ? 'selected' : '' }}>India</option>
<option value="Pakistan" {{ old('country') ?? $country == 'Pakistan' ? 'selected' : '' }}>Pakistan</option>
</select>
 
// Laravel 9
<select name="country">
<option value="India" @selected(old('country') ?? $country == 'India')>India</option>
<option value="Pakistan" @selected(old('country') ?? $country == 'Pakistan')>Pakistan</option>
</select>

Tip given by @VijayGoswami

Enjoyed This Tip?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses

[NEW] Building a Typical Laravel SaaS

11 lessons
1 h 36 min

Laravel 12 For Beginners: Your First Project

15 lessons
1 h 32 min

Laravel HTTP Client and 3rd-Party APIs

7 lessons
50 min

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.