如何通过API Laravel处理用户注册 [英] How to handle User Registration via API Laravel

查看:143
本文介绍了如何通过API Laravel处理用户注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读和观看有关Laravel API开发的一些教程.尽管我曾经使用过Laravel,但我完全不熟悉API开发.

I have being reading and watching some tutorials about API development in Laravel. I am new to API development entirely although I have used Laravel a bit.

在我经历的所有教程中,他们进行了处理:登录,获取一些数据,更新信息,删除信息,甚至将一些信息插入数据库.

From all the tutorials I have gone through, they handled: login, get some data, update information, delete information, and even insert some information into the database.

我的问题是,这些教程都没有处理用户注册之类的问题.

My problem is that none of this tutorials handle something like a user registration.

Route::group(array('prefix' => 'api/v1', 'before' => 'auth.basic'), function()
{
    Route::resource('users', 'UsersController');
    Route::resource('messages', 'MessagesController');
});

根据上面的代码,它假定用户必须先注册才能访问auth.basic的控制器原因.

From the code above, it assumes that user must have registered before gaining access to the controllers cause of the auth.basic.

所以,我的问题是:如何处理注册?因为似乎我不会将其与上面的代码分组.

So, my question is this: How can I handle registration? cause it doesn't seem I will group it with the codes above.

推荐答案

您不能将注册路由放置在具有auth.basic过滤器的路由组中.然后,只有登录的用户才能注册.

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'));

URL将变为: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'));
});

URL将变为:http://yourhost/api/v1/register

然后在UserController中创建一个getRegister()postRegister()方法:

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. 
 }

有很多教程可以帮助您在Laravel中进行用户注册,

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

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

这篇关于如何通过API Laravel处理用户注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆