Select DropDown Option Selected In Laravel

Today, We want to share with you Select DropDown Option Selected In Laravel.In this post we will show you dynamic select option in laravel, hear for how to show selected value in dropdown in laravel 7/6 we will give you demo and example for implement.In this post, we will learn about Select Selected value of a dropdown in laravel 7/6 with an example.

Select DropDown Option Selected In Laravel

There are the Following The simple About Select DropDown Option Selected In Laravel Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel select option selected from database, so the Set selected option in dynamically created drop down menu in Laravel for this example is following below.

Read Also:  PHP Codeigniter load data while Ajax Infinite scrolling Pagination

Example 1: laravel get selected value from dropdown in controller

// Controller
public function index()
{
    $prioritys = Prioritys::all();
    $selectedPriority = User::first()->role_id;

    return view('my_view', compact('prioritys', 'selectedPriority');
}

And then in your view

<select class="form-control m-bot15" name="role_id">
    @if ($prioritys->count())
        @foreach($prioritys as $prtval)
            <option value="{{ $prtval->id }}" {{ $selectedPriority == $prtval->id ? selected="selected" : '' }}>{{ $prtval->name }}</option>     
    @endif

</select>

Example 2 : laravel select option selected from database

// Controller

public function index()
{
    $prioritys = Prioritys::lists('name', 'id');
    $selectedPriority = User::first()->role_id;
    return view('my_view', compact('prioritys', 'selectedPriority');
}

//In view
{!! Form::select('role_id', $prioritys, $selectedPriority, ['class' => 'form-control gstspan') !!}

Example 3: Select Selected value of a dropdown in laravel

//in controller
$oldproducts = Request::old('products');

//Laravel Blade view files
@foreach ($allproducts as $key => $value)
  $selected = '';
  @if( $value == $oldproducts )
    $selected = 'selected="selected"';
  @endif
  <option value="{{ $key }}" {{ $selected }} />{{ $value }}</option>
@endforeach

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  laravel 6 Retrieve data using jQuery Ajax

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Selects DropDowns Option Selected In Laravel.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.