gpt4 book ai didi

laravel - 如何使用 Laravel 在下拉列表中显示数据库中的选定值?

转载 作者:行者123 更新时间:2023-12-03 23:29:49 25 4
gpt4 key购买 nike

我想在页面加载时将数据库中的选定值显示到下拉列表中。

我的 Controller 索引功能是:

public function index()
{
$country_data =DB::table('country')->select('country_id','country_name')->get();
$profile_data= DB::table('profiles')->select('*')->where('id',$user_id)->first();
return view('profile_update',compact('profile_data','country_data'));
}

数据库中高度的列名是:高度

我在 profile_update.blade.php 的下拉菜单是
<select class="select4" name="country" id="country">
<option value="">Please Select</option>
@foreach($country_data as $country)
<option value="{{$country->country_id}}" {{$country_data->country == $country->country_id ? 'selected' : ''}}>{{$country->country_name}}</option>
@endforeach</select>

最佳答案

这是我如何执行此操作的示例:

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

关于laravel - 如何使用 Laravel 在下拉列表中显示数据库中的选定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50970020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com