Display option of select as selected with blade directive Laravel

Created at 22-Aug-2022 , By samar

Display option of select as selected with blade directive Laravel

With this article, we will examine several different instances of how to solve the "Display option of select as selected with blade directive Laravel".

Here we have a blade directive `@selected` in Laravel 9 to display the option of select box as selected with condition. Like if we want to display the old value to be selected of the select box which we have selected while submit the form data then `@selected` directive is very helpful to do so.

Syntax: @selected(old('version') == $version)

  • <select name="version">
        @foreach ($product->versions as $version)
            <option value="{{ $version }}" @selected(old('version') == $version)>
                {{ $version }}
            </option>
        @endforeach
    </select>
    
  • Select option to be selected while creating a record in Laravel using old helper method

    <option value="{{ $company->id }}" @if(old('company') == $company->id) selected @endif>
    	{{ $company->name }}
    </option>
    

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.