I am trying to route to a RESTful controller using the following in app/routes.php:

我正在尝试在app/routes.php中使用以下方法来访问一个RESTful控制器。

Route::controller('register', 'RegisterController');

Route::get('/', 'HomeController@showWelcome');

In my app/controllers/RegisterController.php file I have added the following:

在我的应用程序/控制器/ RegisterController。我添加了以下内容:

<?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);
    }
}

I am getting the following error:

我得到了以下错误:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

Symfony \组件\ HttpKernel \ Exception \ NotFoundHttpException。

When I run php artisan routes in terminal I get:

当我在终端运行php artisan路由时:

+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
| 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 |                |               |
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+

I don't understand why register is showing twice in the URI and the second GET action is missing and why I am getting this error.

我不明白为什么寄存器在URI中显示两次,第二个GET操作丢失了,为什么会出现这个错误。

2 个解决方案

#1


5

If you are using RESTful API, the best way is in your route,

如果您使用的是RESTful API,最好的方法是在您的路径中,

Route::resource('register', 'RegisterController');

And change your public function getRegister() to public function index() and public function postRegister() to public function store()

将您的公共函数getRegister()改为public function index()和public function postRegister()到public function store()

Then the index() can be access using GET http://localhost/laravel/register and the store() using POST http://localhost/laravel/register

然后,索引()可以通过访问http://localhost/laravel/register并使用http://localhost/laravel/register来访问。

Chaneg the http://localhost/laravel/ with yours.

Chaneg: http://localhost/laravel/与您的。

And the same way the update($id) is used for update and destroy($id) is used for delete

和更新($id)用于更新和销毁($id)的方式相同,用于删除。

更多相关文章

  1. 使用jquery / ajax在CodeIgniter控制器内调用函数
  2. thinkphp3.2【空操作和空控制器使用】
  3. 在Yii中获取当前控制器和操作ID
  4. 从模型到控制器并返回到模型的数据
  5. 我是对的,InnoDb比MyISAM更适合频繁的并发更新和插入吗?
  6. 将JSON ID键插入到ng-click指令中,然后将其传递到另一个控制器
  7. 如何从控制器内的javascript函数调用角范围函数
  8. AngularJS我在哪里可以访问加载的控制器的范围?
  9. 角度连接2控制器通过1服务与ES6语法

随机推荐

  1. 【源码】Android 面包屑导航效果源码、An
  2. Android AsyncTas开发
  3. 美国Android占28%份额 摩托Droid最受欢迎
  4. Android 模拟器横屏竖屏切换设置
  5. Android ContentProvider 多进程multipro
  6. android EditText inputType
  7. .Net 转战 Android 4.4 日常笔记(6)--Andro
  8. Android(安卓)Bluetooth
  9. Android RelativeLayout 的属性
  10. android中使用 EditText 时,设定 inputTyp