Installing Sentry 2.1 into Laravel 4.2 for Basic Authentication

Before You Start

Be aware while i’m going to go through the entire process of installing Sentry and handling all the MVC stuff i’m going to assume you already have Laravel up and running. If you haven’t already set up Composer and Laravel then check out the Composer Download and the Laravel Quickstart guide.

Add the Package into Laravel

Use the composer require command opposed to manually adding it to the composer.json file and running composer update. You don’t want to accidentally upgrade packages you aren’t prepared to test for at this point in your development lifecycle.

Update app.php

Open app/config/app.php and update providers and aliases arrays with the following changes.

Running Sentry Migrations

You can run the migrations that are located in the  /vendor/cartalyst/sentry/src/migrations folder by running the following commad:

If you decide to do any database changes you should be adding your on migrations to change anything Sentry does. Running an php artisan migrate:rollback will rollback the migrations in that folder so you don’t need to move them into your own migrations folder.

Saving the Sentry Configuration File

Running this command will store the configurations in app/config/packages/cartalyst/sentry/config.php where you can review and modify and changes you need.

Some Important Config Defaults

  • key =  cartalyst_sentry: You don’t have to change this but if you develop locally with several different laravel apps you may want to. Otherwise you may run into cross site cooking sharing since everything is probably coming from localhost.
  • login_attribute =  email: If you would rather authenticate with a username field you’d need to add a new migration to create it and then configure that here.

Updating the User Model

Replace ‘extends eloquent‘ with ‘extends \Cartalyst\Sentry\Users\Eloquent\User‘ 

Sentry is now successfully installed in Laravel. It doesn’t do you much good at this point but I will go over how to set up seeders, routes, controllers, and views in my next post.