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.

  Laravel 7 jQuery Ajax Request Tutorial

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');
}

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.


Download Project Scripts

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 :

  Laravel 6 - Simple Pagination Example Tutorial

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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel Roles Permissions Example Tutorial From Scratch
  2.   Laravel 6 Ajax post data Example
  3.   PHP MySQLi Insert Update Delete Query Builder
  4.   jQuery Facebook Like Infinite Scroll Pagination in PHP MySQLi
  5.   ng-pattern Email Validation using Angular Example
  6.   PHP Codeigniter load data while Ajax Infinite scrolling Pagination
  7.   laravel 6 Retrieve data using jQuery Ajax
  8.   Angular 9/8 Material Checkbox Examples
  9.   PHP GET HTML source code WebPages using DOM Parser
  10.   Create Laravel Live Search Using Ajax

Leave a Reply

Your email address will not be published. Required fields are marked *