Laravel 5.4将选项选项值传递给Route :: get [英] Laravel 5.4 passing form select option value to a Route::get
问题描述
在users.index刀片页面中,我列出了表中数据库中的所有用户。
所有用户都属于一个分区。有些地区拥有更多的用户,然后是另一个地区。
在此表格视图的顶部,我创建了一个带有选择字段的表单。这些选项包含10个地区的ID:
< form class =form-horizontalmethod =GETaction = /用户/区 >
< div class =form-group col-md-5>
< option value =1>阿姆斯特丹< / option>
< option value =2> Arnhem< / option>
< option value =3>阿森< / option>
< option value =4>格罗宁根< / option>
< option value =5> Leeuwarden< / option>
< option value =6>鹿特丹< / option>
< option value =7> Sittard< / option>
< option value =8>蒂尔堡< / option>
< option value =9> Utrecht< / option>
< option value =10> Antillen< / option>
< / select>
< / div>
< div class =form-group col-md-4 col-md-offset-1>
< button class =btn btn-md btn-primary> Haal gegevens op< / button>
< / div>
< / form>
当我把网址 http:// localhost / users / district / 5 在手动浏览器中向我显示只有ID为5的区域的用户的表视图。 p>
这是我的UsersController:
public function perDistrict($ district)
{
$ users = User :: where('district_id',$ district)
- > paginate(12);
$ totalusers = User :: count();
return view('users.index',compact('users','totalusers'));
}
我想使用表单来获得结果,但是当我提交时它显示给我这个网址的格式: http:// localhost / users / district?district = 5 < a>,它当然不会给我任何结果。
如何将它转换为URL http:// localhost / users / district / 5 ?
这是我的路线:
Route :: get('users / district / {district}','UsersController @ perDistrict');
希望有人可以帮助我。
https://www.codecourse.com/课程/ laravel-fundamentals / 729 为我做了一些自己的定制技巧。
I am trying to do the following within my Laravel 5.4 project.
In a users.index blade page I am listing all users from a database in a table. All the users belong to a district. Some districts have more users then the other.
At the top of this table view I created a form with a select field. The options hold the id's for the 10 districts:
<form class="form-horizontal" method="GET" action="/users/district">
<div class="form-group col-md-5">
<select name="district" class="form-control">
<option value="1">Amsterdam</option>
<option value="2">Arnhem</option>
<option value="3">Assen</option>
<option value="4">Groningen</option>
<option value="5">Leeuwarden</option>
<option value="6">Rotterdam</option>
<option value="7">Sittard</option>
<option value="8">Tilburg</option>
<option value="9">Utrecht</option>
<option value="10">Antillen</option>
</select>
</div>
<div class="form-group col-md-4 col-md-offset-1">
<button class="btn btn-md btn-primary">Haal gegevens op</button>
</div>
</form>
When I put the URL "http://localhost/users/district/5" in manually in the browser it shows me a table view with only users from the district with the ID of 5.
This is my UsersController:
public function perDistrict($district)
{
$users = User::where('district_id', $district)
->paginate(12);
$totalusers = User::count();
return view('users.index', compact('users', 'totalusers'));
}
I would like to use the form to get me the results but when I submit the form it show me this URL: "http://localhost/users/district?district=5" and it gives me no result of course.
How can I convert that to the URL "http://localhost/users/district/5" ?
This my route:
Route::get('users/district/{district}', 'UsersController@perDistrict');
Hope someone can help me.
https://www.codecourse.com/lessons/laravel-fundamentals/729 did the trick for me with some own customization.
这篇关于Laravel 5.4将选项选项值传递给Route :: get的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!