首页 > 解决方案 > 下拉过滤器在 Laravel 5.8 中不起作用

问题描述

我尝试使用以下代码进行输入下拉过滤器:

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

但是,我的代码没有按我的预期运行(如下图所示) - 代码只调用数据库中的第一行。我应该用代码编辑什么?

错误

标签: laraveldropdown

解决方案


我自己也有这个问题,这就是我使用的:

                         <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');

希望这对您有所帮助!


推荐阅读