我正在尝试使用 app/routes.php 中的以下内容路由到 RESTful 控制器:
Route::controller('register', 'RegisterController');
Route::get('/', 'HomeController@showWelcome');
在我的 app/controllers/RegisterController.php 文件中,我添加了以下内容:
<?php
class RegisterController extends BaseController
{
public function getRegister()
{
return View::make('registration');
}
public function postRegister()
{
$data = Input::all();
$rules = array(
'first_name' => array('alpha', 'min:3'),
'last_name' => array('alpha', 'min:3'),
'company_name' => array('alpha_num'),
'phone_number' => 'regex:[0-9()\-]'
);
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
return 'Data was saved.';
}
return Redirect::to('register')->withErrors($validator);
}
}
我收到以下错误:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
当我在终端运行 php artisan routes 时,我得到:
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
| | GET /register/register/{v1}/{v2}/{v3}/{v4}/{v5} | | Register@getRegister | | |
| | POST /register/register/{v1}/{v2}/{v3}/{v4}/{v5} | | Register@postRegister | | |
| | GET /register/{_missing} | | Register@missingMethod | | |
| | GET / | | HomeController@showWelcome | | |
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
我不明白为什么 register 在 URI 中显示两次,而第二个 GET 操作丢失,以及为什么我收到此错误。