如何使下拉选择框为表格?

时间:2019-12-10 03:43:37

标签: html laravel

这个想法是我有这两个select box来过滤用户表的数据

html代码:

<select name="category_id" required>
  <option value=""> Category </option>
     @foreach (\App\Category::all() as $category)
        <option value="{{ $category->id }}">{{ $category->name }}</option>
     @endforeach
</select>

<select name="governorate_id" required>
   <option value=""> Governorate </option>
      @foreach (\App\Governorate::all() as $governorate)
         <option value="{{ $governorate->id }}">{{ $governorate->name }}</option>
      @endforeach
</select>

控制器代码:

public function index()
{
     $AllTopUsers = new User;

     if(request()->has('category_id')){
        $AllTopUsers =  $AllTopUsers->where('category_id' , request('category_id'));
     }

     if(request()->has('governorate_id')){
         $AllTopUsers =  $AllTopUsers->where('governorate_id' , request('governorate_id'));
     }

     $AllTopUsers = $AllTopUsers->verfiy()->active()->paginate(16);

     return view('frontend.AllTopMember', compact('AllTopUsers'));
}     

路线链接:

 Route::get('top-users', 'TopUserController@index')->name('TopUsers');

我停下来直到不知道如何制作这些表格,就像选择任何CategoryGovernorate过滤数据时一样:(

1 个答案:

答案 0 :(得分:0)

  <form action="{{route('where you want to submit')}}">

     <select name="category_id" onchange="this.form.submit()" required>
          <option value=""> Category</option>
           @foreach (\App\Category::all() as $category)
               <option value="{{ $category->id }}">{{ $category->name }}</option>
           @endforeach
     </select>
   </form>

当用户在其中选择任何选项时,onChange change event将会被激活,并且表单将被提交。