php - laravel 4 Route::controller() method returns NotFoundHttpException -
i trying route restful controller using following in app/routes.php:
route::controller('register', 'registercontroller'); route::get('/', 'homecontroller@showwelcome');
in app/controllers/registercontroller.php file have added following:
<?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 saved.'; } return redirect::to('register')->witherrors($validator); } }
i getting following error:
symfony \ component \ httpkernel \ exception \ notfoundhttpexception
when run php artisan routes in terminal get:
+--------+--------------------------------------------------+------+----------------------------+----------------+---------------+ | domain | uri | name | action | before filters | after filters | +--------+--------------------------------------------------+------+----------------------------+----------------+---------------+ | | /register/register/{v1}/{v2}/{v3}/{v4}/{v5} | | register@getregister | | | | | post /register/register/{v1}/{v2}/{v3}/{v4}/{v5} | | register@postregister | | | | | /register/{_missing} | | register@missingmethod | | | | | / | | homecontroller@showwelcome | | | +--------+--------------------------------------------------+------+----------------------------+----------------+---------------+
i don't understand why register showing twice in uri , second action missing , why getting error.
if using restful api, best way in route,
route::resource('register', 'registercontroller');
and change public function getregister()
public function index()
, public function postregister()
public function store()
then index()
can access using get http://localhost/laravel/register
, store()
using post http://localhost/laravel/register
chaneg http://localhost/laravel/
yours.
and same way update($id)
used update , destroy($id)
used delete
Comments
Post a Comment