Laravel Edit DropDown Option Seleted Example

Today, We want to share with you Laravel Edit DropDown Option Seleted Example.In this post we will show you laravel 5.7 get selected value from dropdown in controller, hear for how to show selected value in dropdown in laravel 5.7 using ajax we will give you demo and example for implement.In this post, we will learn about How to get by default select value in dropdown in Edit mode laravel 5.7 with an example.

Laravel Edit DropDown Option Seleted Example

There are the Following The simple About Laravel Edit DropDown Option Seleted Example Full Information With Example and source code.

Read Also:  Generate PDF Files using Laravel 5.7 Dynamically Scripts

As I will cover this Post with live Working example to develop laravel 5.7 select option selected from database, so the laravel 5.7 get selected value from dropdown for this example is following below.

Example 1: Laravel edit select option values

Laravel Controller

public function edit($id)
{
    $suggestions_datas = DB::table('suggestions')->where('id', $id)->get();
    $categories = DB::table('categories')->whereNull('deleted_at')->pluck("name","id");
    return view('suggestions.edit',compact('suggestions_datas','categories'));
}

Laravel Blade file

<div class="form-group ">
    <label class="control-label" for="suggestion_title">Applications's</label>
    <select class="form-control" name="suggestion_app" id="suggestion_app" required="" autofocus="">
    @foreach ($categories as $key => $value)
        <option value="{{ $key }}" {{$suggestions_datas[0]->categories_id == $key ? "selected" : "" }}>{{ $value }}</option>
    @endforeach
    </select>
</div>

Example : 2 laravel 5.7 get selected value from dropdown

<div class="form-group">
    <label class="col-form-label" for="inputDefault">Employee Types</label>

    <select name="emp_types" class="form-control" name="emp_types" id="inputDefault">
    <option @if(old('emp_types',$emp_types) == 'Pending') selected @endif >
        Pending
    </option>
    <option @if(old('emp_types',$emp_types) == 'Completed') selected @endif >
        Completed
    </option>
    </select>
</div>

where simple $emp_types is coming from your model

Read Also:  Get Current User ID from Mysql in Laravel

Example : 3 Select DropDown Option Seleted In Laravel

Laravel Controller

public function index()
{
    $teams = Teams::all();
    $selectedTeam = User::first()->role_id;

    return view('my_view', compact('teams', 'selectedTeam');
}

And then in your view

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

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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

Read Also:  File Type validation using Javascript

I hope you get an idea about Laravel Edit DropDown Option Seleted Example.
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. Read Also:  PHP Get Query String Parameters using Laravel
  2. Read Also:  PHP jQuery AJAX Live check email Availability
  3. Read Also:  PHP Laravel 6 Session-Based Flash Message Example
  4. Read Also:  File Upload in Laravel 7 Example Tutorial
  5. Read Also:  Simple Laravel Dynamic Select Boxes Example
  6. Read Also:  JavaScript Client side Password hashing and encryption
  7. Read Also:  jQuery Add Remove Class on mouseOver mouseOut
  8. Read Also:  How to Merge Two Eloquent Collections in Laravel?
  9. Read Also:  PHP Get Query String Parameters using Laravel
  10. Read Also:  File Upload in Laravel 7 Example Tutorial
CLOSEX