I'm trying to get the selected value from a dropdown in my view through my controller, but it's always returning null
. I really don't know why.
Here is my select dropdown: UPDATED: Here is my full blade view!
@extends('backpack::layout')
@section('header')
<section class="content-header">
<h1>
<span class="text-capitalize">Thành tích tốt nhất ngày</span>
</h1>
<ol class="breadcrumb">
<li><a href="/admin/dashboard">Admin</a></li>
<li><a href="/admin/cache-club-earth">Thành tích tốt nhất ngày</a></li>
<li class="active">List</li>
</ol>
</section>
@endsection
@section('content')
<form method="GET">
Lọc round:
<select id="tablefilter" name="tablefilter">
<option value="0">Hiện tại</option>
@foreach($max as $item)
<option value="{{$item->countRound}}">{{$item->countRound}}</option>
@endforeach
</select>
</form>
<table id="currentRound" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Câu lạc bộ</th>
<th>Quãng đường</th>
<th>Quãng đường trung bình</th>
<th>Xếp hạng</th>
<th>Số thành viên</th>
<th>Ngày xếp hạng</th>
</tr>
</thead>
<tbody>
@foreach ($result as $item)
<tr>
<td>{{$item->name}}</td>
<td align="right">{{number_format($item->total_distance/1000, 2)}} km</td>
<td align="right">{{number_format($item->avg_distance/1000, 2)}} km</td>
<td align="right">{{number_format($item->rank)}}</td>
<td align="right">{{$item->total_member}}</td>
<td>{{$item->created_at}}</td>
</tr>
@endforeach
</tbody>
</table>
<script>
$(document).ready(function () {
$('#currentRound').DataTable({
"paging" : true,
"aaSorting": [[3, 'asc']],
"dom": '<"top"f>rt<"bottom"lp><"clear">',
});
});
</script>
@endsection
@section('after_styles')
<!-- DATA TABLES -->
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<!-- CRUD LIST CONTENT - crud_list_styles stack -->
@stack('crud_list_styles')
@endsection
@section('after_scripts')
<script type="text/javascript" charset="utf8"
src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf8"
src="https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap.min.js"></script>
@endsection
And in my controller:
public function index(Request $request) {
$round = $request->input('tablefilter');
//dd($round);
$mMile = new MilestoneEarth();
$max = $mMile->getRound();
return view('admin.cacheClubEarth.index',['result' => $result, 'max' => $max]);
}
It's return [] with $request->all() and null with $request->tablefilter
I really don't know how to do with this!
Can you help me!
Thank you very much!
</div>
You can do : dd(request->all()); for check the data. I think you don't have to use the input function. Try this :
$round = $request->tablefilter;
you need to send the form value either submit using button or use ajax for it
here the basic submitting data via form (i specified action in case you go to different page)
<form method="GET" action="{{url('/to/index/controller/you-want')}}>
Lọc round:
<select id="tablefilter" name="tablefilter">
<option value="0">Hiện tại</option>
@foreach($max as $item)
<option value="{{$item->countRound}}">{{$item->countRound}}</option>
@endforeach
</select>
<button class="something">Update</button>
</form>
@foreach($max as $item)
<option value="{{$item}}">{{$item}}</option>
@endforeach