Simple Example of Laravel 5 Login System Using Sentry

I will be demonstrate simple Laravel authentication using sentry.Already I have shared Simple theming with laravel 5 and introduction of Authorization and Authentication of Users in laravel 5 Using Sentry.

I got huge response and request about full register and login system using laravel 5 with sentry, so let’s start entire process of authorization and authentication of users.

We will go through following steps :

  • Configure Sentry with Laravel 5
  • I will create authorization sentry package tables using migration
  • Created Login/register and thanks ui pages using Gentellela Admin bootstrap theme, you can get more information from theming in laravel 5 this tutorial
  • .

  • Routing using sentry methods and laravel 5.
  • Created login/register and forgot_password action method in controller and render UI.

How to configure Sentry with Laravel 5:

Step 1: You need to add dependency in composer.php file like below,

Step 2: Add providers and aliases in config/app.php file.

Added senetry in provider array

Added in aliases array

You can also check other recommended tutorials of Lumen/Laravel,

Step 3: in command line run composer update or install composer command to install sentry dependency.

D:\xampp\htdocs\testlogin> composer update

Now you have configured sentry with your project.

How to Migrate Database table of Sentry package in Laravel 5

Please make sure your database connected with laravel projects,if not please check config/database.php or you can configure using .env file.

php artisan vendor:publish --provider="Cartalyst\Sentry\SentryServiceProvider"

Now added theme and layout for login and register view,You can get more information from Simple Laravel Layouts using Blade Template and Bootstrap Theme tutorial.

Defining routemiddleware class to verify logged-in user and guest.We need to add below lines in Http/kernel.php file.

Created VerifySentryGuest.php file in App\Http\Middleware\ folder and put below code into this file.

Created VerifySentryLoggedIn.php file in App\Http\Middleware\ folder and put below code into this file.

We will refine User model , we need to open app/User.php file and delete all content, We need to add below code into this file.

Here we are using SentryModel User model class that can be later use in user controller file.

We will create new user controller in Laravel 5 using below command

D:\XAMPP\htdocs\test_login>php artisan make:controller UserController

Above command will create UserController.php file in controller directory.

Define Routing In laraval 5 Using Sentry

Now added routes in /app/http/route.php file

Here we have added guest route, The Guest user can access login,register and thanks page.We are redirecting user to login page if user haven’t logged in system or guest.

Now we will defined Logged-in user access page, we can add more route which can be accesses by logged-in user.

So we have defined all routes that need for authenticate user.

We will create new Register view file register.blade.php in resources/views/user/guest/ folder and use below code.

Added controller method in UserController.php file to register user,

Now open http://localhost/laraveltest/user/register on browser,You can see register page.You need to fill all details and click submit button after successfully validate all fields you will redirected on Thankspage which is not created yet, now we will create thanks page.

laravel register

We will create register.blade.php file in resources/view/pages/ folder and added below code

thanks page

Added action in UserController.php file

Now we will create login page and controller action,create Login view file login.blade.php in resources/views/user/guest/ folder and add below code into this file.

Added login() controller method in UserController.php file to login user,

Now open http://localhost/laraveltest/user/login on browser,You can see login page.You need to fill email and password and click login button after successfully validate all fields you will redirected on Dashboard page which is not created yet, now we will create Welcome Dashboard page.

login laravel

We will create new dashboard.blade.php file in resources/views/member/ folder and put below code into this file,

this is my home page


Now we will create Dashbord action methos in UserController.php file,

Finally define logout controller action, We need to add new below method in UserController.php file.


This laravel 5 tutorial help to understand login,register and logout functionality using sentry package.You can authenticate user using this laravel 5 tutorial and redirect user to dashboard.We have also learnt about add layout using blade template in laravel 5 with database migration script.