How to handle User Registration via API Laravel

橙三吉。 提交于 2019-12-04 07:38:05

You can't place the registration routes in a route group with a auth.basic filter. Then only users that are logged in can register.

So you should make new routes for registration:

// Opens view to register form
Route::get('register', array('as'=>'register', 'uses'=>'UserController@getRegister'));
// Handles registering
Route::post('register', array('uses'=>'UserController@postRegister'));

The URL would become: http://yourhost/register

Or if you still want to use your prefix, you can group:

Route::group(array('prefix'=>'api/v1'), function(){
  // Opens view to register form
  Route::get('register', array('as'=>'register', 'uses'=>'UserController@getRegister'));
  // Handles registration
  Route::post('register', array('uses'=>'UserController@postRegister'));
});

The URL would become: http://yourhost/api/v1/register

Then you create a getRegister() and postRegister() method in your UserController:

<?php

class UserController extends BaseController{

 public function getRegister(){
   // Return register form
   return View::make('users.register');
 }

 public function postRegister(){
   // Validate post info and create users etc. 
 }

There are tons of tutorials to help you with user registration in Laravel,

http://code.tutsplus.com/tutorials/authentication-with-laravel-4--net-35593

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!