我在Laravel中的路由函数添加了一个问号(?),而不是斜杠(/)
route('servers.index', 321); // http://domain/public_html/server?321
我希望它返回 http://domain.com/public_html/clientarea/server/321
路线:
Route::group(['prefix' => 'clientarea'], function()
{
Route::get('/', 'UsersController@index');
Route::get('server/{id}', 'ServersController@index');
});
Route::resource('users', 'UsersController');
Route::resource('servers', 'ServersController');
您应该研究 route()
函数应该如何工作。例如,如果您计划使用 route()
引用路由,则应命名该路由。一旦你命名了它,你必须确保你正确地传入了参数,正如Lukas所说。
如果 Laravel 找不到为路由定义的匹配参数,它将默认使参数成为查询字符串的一部分。由于路由不存在,因此它无法找到与要传入的内容匹配的参数。
查看文档:http://laravel.com/docs/4.2/routing#named-routes
route
函数需要一个参数数组。您可以按参数名称或顺序传递值
route('servers.index', array(321));
或者这个(假设参数被称为id
route('servers.index', array('id' => 321));
来自Laravel论坛
$url = URL::route('welcome') . '#hash';
return Redirect::to($url); // domain.com/welcome#hash
http://laravel.io/forum/02-07-2014-how-to-append-hashtag-to-end-of-url-with-redirect