[英]Laravel Routing: How to route when using URL query string?
I have a route - let's call it stats . 我有一条路线 - 让我们称之为统计数据 。 Here is what my routing currently looks like: 这是我的路由目前的样子:
Route::get('stats', 'StatsController@index');
Route::get('stats/{query}', 'StatsController@store');
My goal is to show stat data if someone visits /stats and to store stat data if someone visits a URL similar to /stats?name=John&device=Android . 我的目标是显示有人访问/统计数据的统计数据,并在有人访问类似于/ stats的网址时存储统计数据?name = John&device = Android 。
How would I then route if there is a query string attached to my namespace stats ? 如果有一个查询字符串附加到我的命名空间统计信息 ,我将如何路由?
Something like this? 像这样的东西?
Route::get('stats/?name=*&device=*', 'StatsController@store');
routes.php routes.php文件
Route::get('stats', 'StatsController@index');
StatsController StatsController
public function index()
{
if(Input::has('name') and Input::has('device')))
return $this->store();
// Show stat ...
}
public function store()
{
$input = Input::only('name', 'device');
// Store stat ...
}
although it seems a pefect scenario for a RESTFUL controller. 虽然它似乎是一个RESTFUL控制器的完美场景。 Whoever is sending the input should do it with a POST request 无论谁发送输入,都应该使用POST请求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.