How to show selected value from database in dropdown using Laravel?

后端 未结 2 1006
野趣味
野趣味 2021-01-06 17:37

I want to show selected value from database into dropdown list on page load.

My controller index function is :

public function index()
{ 
 $country_d         


        
相关标签:
2条回答
  • 2021-01-06 18:09

    This is a example of how I do this:

    <select class="js-states browser-default select2" name="shopping_id" required id="shopping_id">
            <option value="option_select" disabled selected>Shoppings</option>
            @foreach($shoppings as $shopping)
                <option value="{{ $shopping->id }}" {{$company->shopping_id == $shopping->id  ? 'selected' : ''}}>{{ $shopping->fantasyname}}</option>
            @endforeach
        </select>
    
    0 讨论(0)
  • 2021-01-06 18:21

    @Sarita Sharma show the error(s). Maybe then anyone help you to resolve this problem. Show data in colections in controler - use dd e.g.

    dd($country_data);
    dd($profile_data);
    

    Do you want to display the country in the view with the appropriate Height value from profile_data?

    Ps. How to put the code, please use the formatting code - put the code in `` and use camelCase in value name (maintaining good PSR-1 practice) - it is easier to read code.

    0 讨论(0)
提交回复
热议问题