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');
});
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With