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.

Read Also:  AngularJS Random Strong Password Generator

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.

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>     


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"';
  <option value="{{ $key }}" {{ $selected }} />{{ $value }}</option>

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  Laravel Select Dropdown From Database Example


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 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.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  load data dynamically on page scroll using jquery ajax and php
  2. Read Also:  How to show selected value from database in dropdown using Laravel?
  3. Read Also:  How to change a select’s options based on another dropdown using javascript?
  4. Read Also:  Laravel 5/6/7 CRUD Operations Example Step By Step
  5. Read Also:  Triggering callback after user stops typing jQuery
  6. Read Also:  sql unique count and use distinct in sql
  7. Read Also:  How to Open URL in New Window using jQuery?
  8. Read Also:  Laravel Dependent Dropdown Example Tutorial From Scratch
  9. Read Also:  Angular NgClass - How to Add Dynamic Class in Angularjs?
  10. Read Also:  jQuery Facebook Like Infinite Scroll Pagination in PHP MySQLi