I am using Laravel 5.1 and trying to implement user authentication. Basically no routes should be accessible without loggin in.
The built in trait (AuthenticatesAndReg
How to use the build-in authentication in Laravel 5.1
Laravel 5.1 has build in authentication and it works almost out of the box.
There are few step to do, so you will be able to use the nice default build in Authentication template in Laravel 5.1. So you do not need to invent that wheel again like Laravel 4.0.
1- Install fresh copy of Laravel (follow this http://laravel.com/docs/5.1) I did it by simply using this command
composer create-project laravel/laravel --prefer-dist
2- Create auth
folder in views resources\views\auth
and copy all resources files to it from https://github.com/laravel/laravel/tree/5.0/resources/views/auth
3- Create css
and fonts
folder inside public
folder and copy both folders content from resources https://github.com/laravel/laravel/tree/5.0/public
4- Update your route file like below
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
regarding to https://github.com/laravel/laravel/blob/5.0/app/Http/routes.php
5- Create empty database in your MySQL.
6- Update your .env
file with database info etc.
7- Run php artisan migrate
8- Go to browser and write http://YourLaravelHostProject/auth/register
9- (Optional) If you want to change /home
landing page after login/registration process edit AuthController.php
in app\Http\Controllers\Auth
:
After this line
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
Add the code with your location
//forward after login
protected $redirectPath = '/YourLocation';
That is it. Now you have the default login/register/reset password template working. You can modify it for further use.
php artisan migrate results
Browser snapshot of Login page
It is also possible to make a simpler authentication template by following Laravel documentation.
Laravel authentication documentation http://laravel.com/docs/5.1/authentication