我的UserController
:
public function verifyUsername()
{
$rules = array(
'username' => 'required|max:30|unique:users,username'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
return Response::json(array(
'success' => 'false',
'errors' => $validator->messages()
), 400);
}
else
{
return Response::json(array(
'success' => 'true'
));
}
}
我希望有这样的网址路径:
/users/verify/username/{username}
如何将路由中的username
变量传递给控制器中的方法?
答案 0 :(得分:1)
您传入的数组uses
设置为ControllerName@methodName
您可能需要查看Named Routes以获取更多信息。
<强> routes.php文件强>
Route::get('users/verify/username/{username}',
array('uses' => 'UserController@verifyUsername'));
<强>控制器强>
public function verifyUsername($username)
{
//it would be nice if this works, but I don't think it will
$validator = Validator::make(Input::get('username'), $rules);
// something like this should work
$data = ['username' => $username];
$validator = Validator::make($data, $rules);
}