29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Authentication 144<br />

Authenticating<br />

Now that you have routes and views setup for the included authentication controllers, you are ready<br />

to register and authenticate new users for your application. You may simply access your defined<br />

routes in a browser. The authentication controllers already contain the logic (via their traits) to<br />

authenticate existing users and store new users in the database.<br />

When a user is successfully authenticated, they will be redirected to the /home URI, which you will<br />

need to register a route to handle. You can customize the post-authentication redirect location by<br />

defining a redirectPath property on the AuthController:<br />

.<br />

1 protected $redirectPath = '/dashboard';<br />

When a user is not successfully authenticated, they will be redirected to the /auth/login URI. You<br />

can customize the failed post-authentication redirect location by defining a loginPath property on<br />

the AuthController:<br />

.<br />

1 protected $loginPath = '/login';<br />

The loginPath will not change where a user is bounced if they try to access a protected route. That<br />

is controlled by the App\Http\Middleware\Authenticate middleware’s handle method.<br />

Customizations<br />

To modify the form fields that are required when a new user registers with your application,<br />

or to customize how new user records are inserted into your database, you may modify the<br />

AuthController class. This class is responsible for validating and creating new users of your<br />

application.<br />

The validator method of the AuthController contains the validation rules for new users of the<br />

application. You are free to modify this method as you wish.<br />

The create method of the AuthController is responsible for creating new App\User records in your<br />

database using the Eloquent ORM. You are free to modify this method according to the needs of your<br />

database.<br />

Retrieving The Authenticated User<br />

You may access the authenticated user via the Auth facade:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!