authentication - How to handle User Registration via API Laravel -
i have being reading , watching tutorials api development in laravel. new api development entirely although have used laravel bit.
from tutorials have gone through, handled: login, data, update information, delete information, , insert information database.
my problem none of tutorials handle user registration.
route::group(array('prefix' => 'api/v1', 'before' => 'auth.basic'), function() { route::resource('users', 'userscontroller'); route::resource('messages', 'messagescontroller'); });
from code above, assumes user must have registered before gaining access controllers cause of auth.basic
.
so, question this: how can handle registration? cause doesn't seem group codes above.
you can't place registration routes in route group auth.basic filter. users logged in can register.
so should make new routes registration:
// opens view register form route::get('register', array('as'=>'register', 'uses'=>'usercontroller@getregister')); // handles registering route::post('register', array('uses'=>'usercontroller@postregister'));
the url become: http://yourhost/register
or if still want use prefix, can group:
route::group(array('prefix'=>'api/v1'), function(){ // opens view register form route::get('register', array('as'=>'register', 'uses'=>'usercontroller@getregister')); // handles registration route::post('register', array('uses'=>'usercontroller@postregister')); });
the url become: http://yourhost/api/v1/register
then create getregister()
, postregister()
method in usercontroller
:
<?php class usercontroller extends basecontroller{ public function getregister(){ // return register form return view::make('users.register'); } public function postregister(){ // validate post info , create users etc. }
there tons of tutorials user registration in laravel,
http://code.tutsplus.com/tutorials/authentication-with-laravel-4--net-35593
Comments
Post a Comment