title: How to pass variable with ajax to blade Laravel
body: <p>I want when i select dropdown and pick team to list player who play in that team and only to give me back that specific players...I do this bellow , but i don't know how to send variable from ajax direct in blade and after that to do my thing with foreach :) ... Thanks a lot ...</p>
  
  <p>This is my blade </p>
  
  <pre><code>{!! Form::open(array('url'=&gt;'','files'=&gt;'true')) !!}
  
                          &lt;div class="form-group col-xs-12 mb-2"&gt;
                              {!! Form::select('category',[''=&gt;'Chose Team to See Players']+$teams, null,['class'=&gt;'form-control','id'=&gt;'category']) !!}
  
                          &lt;/div&gt;
  
                          {!! Form::close() !!}
                      &lt;/div&gt;
                      &lt;div class="table-responsive"&gt;
                          &lt;table class="table"&gt;
                              &lt;thead class="bg-yellow bg-lighten-3"&gt;
                              &lt;tr&gt;
                                  &lt;th&gt;Photo&lt;/th&gt;
                                  &lt;th&gt;Name&lt;/th&gt;
                                  &lt;th&gt;Position&lt;/th&gt;
                                  &lt;th&gt;Age&lt;/th&gt;
                                  &lt;th&gt;Edit&lt;/th&gt;
                                  &lt;th&gt;Delete&lt;/th&gt;
                                  &lt;th&gt;Add/Edit Biography&lt;/th&gt;
                              &lt;/tr&gt;
                              &lt;/thead&gt;
                              &lt;tbody&gt;
                              @foreach($players as $player)
  
                                  &lt;tr&gt;
                                      &lt;td&gt;&lt;img src="{{$player-&gt;photo-&gt;file}}" alt="cukaricki-{{$player-&gt;playerName}}" width="150px"&gt;&lt;/td&gt;
                                      &lt;td&gt;{{$player-&gt;playerName}} {{$player-&gt;playerLastName}}&lt;/td&gt;
                                      &lt;td&gt;{{$player-&gt;position}}&lt;/td&gt;
                                      &lt;td&gt;{{$player-&gt;age}}&lt;/td&gt;
                                      &lt;td&gt; {!! Form::open(['method'=&gt;'GET','action'=&gt;['PlayerController@edit',$player-&gt;id]]) !!}
  
                                          &lt;div class="class form-group"&gt;
                                              {!! Form::submit('Edit',['class'=&gt;'badge btn-info btn-sm']) !!}
                                          &lt;/div&gt;
  
                                          {!! Form::close() !!}&lt;/td&gt;
  
                                      &lt;td&gt;
  
                                          {!! Form::open(['method'=&gt;'DELETE','action'=&gt;['PlayerController@destroy',$player-&gt;id]]) !!}
  
                                          &lt;div class="class form-group"&gt;
                                              {!! Form::submit('Delete',['class'=&gt;'badge btn-danger btn-sm']) !!}
                                          &lt;/div&gt;
  
                                          {!! Form::close() !!}
                                      &lt;/td&gt;
  
  
                                          @if($player-&gt;checkBiography($player-&gt;id) == false)
  
                                          &lt;td&gt;
                                              {!! Form::open(['method'=&gt;'GET','action'=&gt;['BiographyController@show',$player-&gt;id]]) !!}
  
                                              &lt;div class="class form-group"&gt;
                                                  {!! Form::submit('Create',['class'=&gt;'badge btn-success btn-sm']) !!}
                                              &lt;/div&gt;
  
                                              {!! Form::close() !!}&lt;/td&gt;
  
                                             @else
                                          &lt;td&gt;
                                          {!! Form::open(['method'=&gt;'GET','action'=&gt;['BiographyController@edit',$player-&gt;id]]) !!}
  
                                          &lt;div class="class form-group"&gt;
                                              {!! Form::submit('Edit',['class'=&gt;'badge btn-warning btn-sm']) !!}
                                          &lt;/div&gt;
  
                                          {!! Form::close() !!}&lt;/td&gt;
                                      @endif
  
                                  &lt;/tr&gt;
  
                              @endforeach
  
                              &lt;/tbody&gt;
                          &lt;/table&gt;
                      &lt;/div&gt;
  </code></pre>
  
  <p>Route</p>
  
  <pre><code>Route::get('/ajax-subcat',function (){
  
      $cat_id = Illuminate\Support\Facades\Input::get('cat_id');
  
      $team=App\Team::where('id',$cat_id)-&gt;first();
  
      $arrays=explode(",",$team-&gt;player_id);
  
      foreach($arrays as $array){
          $players[]=App\Player::where('id',$array)-&gt;first();
  
      }
      return Response::json($players);
  
  });
  </code></pre>
  
  <p>And Ajax:</p>
  
  <pre><code>&lt;script&gt;
  
      $('#category').on('change',function (e) {
  
          console.log(e);
  
          var cat_id = e.target.value;
  
          //ajax
  
          $.get('/ajax-subcat?cat_id='+cat_id,function (data) {
  
              //success data
              $('#ovde').empty();
              $.each(data,function (index,  Obj) {
  </code></pre>
  
  <p>//what to do here how to send $players from route to blade ?!</p>
  
  <pre><code>                );
              });
  
  
          });
  
      });
  
  &lt;/script&gt;
  </code></pre>