我尝试使用以下代码进行输入下拉过滤器:
<div class="col-md-2">
<div class="text-justify" >
<select class="itemName form-control form-filter" style="width:90px;" name="itemName" id="itemName">
@foreach($data as $category){
<option value="{{$category->Umur}}">{{$category->Umur}}</option>
@endforeach
</select>
</div>
</div>
但是,我的代码未按预期运行(如下图所示)-该代码仅调用数据库的第一行。我应该用代码编辑什么?
答案 0 :(得分:0)
<div class="col-md-2">
<div class="text-justify" >
<select class="itemName form-control form-filter" style="width:90px;" name="itemName" id="itemName">
@foreach($data as $category){
<option value="{{$category->Umur}}">{{$category->Umur}}</option>
@endforeach
</select>
</div>
</div>
在{foreach之后删除{并像这样更改值
<div class="col-md-2">
<div class="text-justify" >
<select class="itemName form-control form-filter" style="width:90px;" name="itemName" id="itemName">
@foreach($data as $category)
<option value="{{$category->id}}">{{$category->Umur}}</option>
@endforeach
</select>
</div>
</div>
答案 1 :(得分:0)
我自己也遇到了这个问题,这就是我所使用的:
<div class="form-group">
<div class="btn-group">
<input list="brow" class="form-control"name="instagram_account_id" id="instagram_account_id" placeholder="Search..">
<datalist id="brow">
@if($users->count() > 0)
@foreach($users as $user)
<option value="{{$user->id}}">{{ $user->username }}</option>
@endforeach
@else
No User(s) Found
@endif
</datalist>
</div>
</div>
关于我的控制器:
public function index()
{
$comments = Comment::paginate(10);
$users = InstagramAccount::all();
return view('instagramComments', [
'comments' => $comments,
'users' => $users,
]);
}
然后(如果您要使用它作为一种形式)在控制器中插入:
public function insert(Request $req)
{
$instagram_comment = $req->input('instagram_comment');
$instagram_account_id = $req->input('instagram_account_id');
$data = array('comment'=>$instagram_comment, 'account_id'=>$instagram_account_id);
DB::table('comments')->insert($data);
return redirect('/comments');
}
(如果使用上面的插入内容,请在您的网络路线中使用此代码):
Route::post('/locationsInsert', 'InstagramLocationsController@insert')->middleware('auth');
希望这对您有帮助!