K
K
kkoshakk2016-02-02 16:57:14
MySQL
kkoshakk, 2016-02-02 16:57:14

Authorization error in Laravel?

Once I can go to localhost:8000/auth/register, the registration form opens, I enter data and the user appears in my database and that's it, I can't go to localhost:8000/auth/register anymore to get another user , redirects me to localhost:8000 or throws NotFoundHttpException in RouteCollection.php line 161:
Here's my code, what's wrong?
routes.php
<?php
/*
|----------------------------------------- ---------------------------------
| Route File
|---------------------------------------------------- ---------------------
|
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
/*
|----------------------------------------------------- ---------------------
| Application Routes
|---------------------------------------------------- ---------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => ['web']], function () {
// Registration routes...
Route::get('auth/register', 'Auth\[email protected]');
Route::post('auth/register', 'Auth\[email protected]');
});
AuthController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Models\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|------------------------------------------------ --------------------------------
| Registration &
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login / registration.
*
* var string
*/
protected $redirectTo = '/home';
/**
* Create a new authentication controller instance.
*
* return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'first_name' => 'required|alpha',
' last_name' => 'required|alpha',
'email_address' => 'required|email|unique:users,email_address',
'
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* return User
*/
protected function create(array $data)
{
return User::create([
'first_name' => $data['first_name'],
'last_name' => $data[' last_name'],
'email_address' => $data['email_address'],
'password' => bcrypt($data['password']),
]);
}
}
User.php
<?php namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract {
use Authenticatable, Authorizable, CanResetPassword;
/**
* The database table used by the model.
*
* var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* var array
*/
protected $fillable = ['first_name', 'last_name', 'email_address', 'skype_name', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* var array
*/
protected $hidden = ['password', 'role_id', 'remember_token'];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-02-03
@Astatroth

localhost:8000/auth/logout then you can log into /auth/register again. Laravel automatically authorizes the user after registration.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question