我试图通过我的控制器从视图中的下拉列表中获取所选值,但它总是返回null
.我真的不知道为什么。
这是我的选择下拉列表:更新:这是我的完整刀片视图!
@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
在我的控制器中:
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]);
}
它返回带有 $request->all(( 的 [] 和带有 $request->tablefilter 的 null
我真的不知道该怎么做!
你可以帮我吗!
谢谢!
你可以做 : dd(request->all(((; 来检查数据。我认为您不必使用输入函数。试试这个:
$round = $request->tablefilter;
您需要发送表单值,要么使用按钮提交,要么使用 Ajax 为其发送表单值
这是通过表单提交数据的基本内容(如果您转到其他页面,我指定了操作(
<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