简体   繁体   中英

Fetch data by selected id using dependent dropdown in laravel-8

Here is my scores table, I have some data stored. You can see have one row called match_id..

I can fetch them in my index.blade.php by doing this code and I can select the id number you can see in this image.

<label for="team_name">Match</label>
     <select class="form-control" name="match_id" required="">
          @foreach ($data as $row)
              <option style="color: blue" >{{ $row->match_id }}</option>
          @endforeach
      </select>

I want that If I select any id It will only show only those data which is connected to this id in the table. here is my index.blade.php

<div class="from-group">
            <label for="team_name">Match</label>
            <select class="form-control" name="match_id" required="">
                @foreach ($data as $row)
                        <option style="color: blue" >{{ $row->match_id }}</option>
                @endforeach
            </select>
            <table id="example1" class="table table-bordered table-striped table-sm">
                <thead>
                    <tr>
                        <th>SL</th>
                        <th>Match Name</th>
                        <th>Team Name</th>
                        <th>Player Name</th>
                        <th>Score Name</th>
                        <th>Score Slug</th>
                    </tr>
                </thead>
                <tbody>

                    @foreach ($data as $key => $row)
                        <tr>
                            <td>{{ $key + 1 }}</td>
                            <td>{{ $row->matchh->match_name }}</td>
                            <td>{{ $row->team->team_name }}</td>
                            <td>{{ $row->player->player_name }}</td>
                            <td>{{ $row->score_name }}</td>
                            <td>{{ $row->score_slug }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>

Here is my PublicController.php

public function index()
{
   $match = Matchh::all();
   $data = Score::all();
   $team = Team::all();
   $score = Score::all();
   return view('public.index',compact('match','data','team'));
}
Route::group(['before'=>'auth'], function(){
    Route::get('/ajax-match',function () {
        $matchh = Input::get('match_name');
        $values = DB::table('matchh')->where('id','>',0)->where('id','=',$id)->where('status', 1)->lists('id', 'match_name');
        return Response::json($values);
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM