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.

Also Read :  Laravel Integrate CKEditor Example Tutorial

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

Also Read :  Exporting HTML Table To CSV File Using Angularjs

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.

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.

Gondaliya Jaydeep

Hi, I’m Jaydeep Gondaliya, PHP developer.Pakainfo.com is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development.Any visitors of this site are free to browse our tutorials, live demos, Examples and download scripts.If you have a project that you want to get started, launch quickly, contact me. Email : [email protected]