Unify Laravel Auth

To use this package, you must first obtain access to the Unify Composer repository. You must also have received a Unify Key.


  1. Add the Unify composer repository to your project's composer.json file.
	"repositories": [
            "type": "composer",
            "url": ""
  1. Install the package by running the following command in your project directory.
composer require getunify/laravel-auth

During installation, you might be prompted by Composer to enter your repository credentials.

  1. After installation, open config/auth.php and change your default guard to unify.
'defaults' > [
    'guard' => 'unify',
    'passwords' => 'users',
  1. Add your Unify Key to your .env file.


If a user is not logged in and visits a protected page, they are redirected to Unify and asked to log in first. After the user logs in, they automatically return to the protected page they intended to visit.

Require user authentication to view a page

Use the auth middleware to protect a route with authentication.

// In your routes file, for example: routes/web.php

// In a controller, for example: app/Http/Controllers/FooController.php
class FooController extends Controller
    public function __construct() 

Only allow a specific access level to view a page

Pages that require a certain access level can be protected with the unify.level middleware.

// Only allow users with access level 1

// Only allow users with access level 0 or 2, but not 1

See the Laravel documentation to learn more about middleware:

Check if the user is logged in

Use Laravel's authentication helpers to determine if the user is logged in.

if (Auth::check()) {
    // Run code when user is authenticated

if (Auth::guest()) {
    // Run code when user is not logged in

Reading user information

Use Laravel's authentication helpers to retrieve user information.

The returned value from Auth::user() is an instance of \Unify\LaravelAuth\Session\Profile. If there is no user logged in, the returned value is null.

You can type-hint \Unify\LaravelAuth\Session\Profile on controller methods to automatically get the user object injected by Laravel.

From the user object you can read information.

use Illuminate\Support\Facades\Auth;

$user = Auth::user();

Available properties

$user->id; // "be9f339215128334459eed3a7c6b40cf"
$user->initials; // "J.E."
$user->name; // "Jane Doe"
$user->firstName; // "Jane"
$user->lastName; // "Doe"
$user->formalName; // "J.E. Doe"
$user->indexableName; // "Doe, Jane"
$user->email; // ""
$user->timezone; // "Europe/Amsterdam"
$user->locale; // "nl"
$user->onekeyId; // "WNLR00000000"
$user->registrations; // ["foo_number" => "TEST001UNIFY", "bar_number" => "TEST002UNIFY"]

$user->address->organization; // "Acme Inc."
$user->address->street; // "Example St."
$user->address->number; // "42"
$user->address->letter; // "a"
$user->address->postalCode; // "1010AB"
$user->address->city; // "Amsterdam"
$user->address->country; // "NL"

Available methods

$user->hasAccessLevel0(); // true | false
$user->hasAccessLevel1(); // true | false
$user->hasAccessLevel2(); // true | false

$user->isDeveloper(); // true | false
$user->isEmployee(); // true | false
$user->isAdministrator(); // true | false

Logging out

To end the user's session, have them visit the logout route of your application.

On top of the core we build a vast variety of solutions

They extend your digital power and enrich your processes.


Unify Europe
Sales: Pieter Smit
Ankerweg 2
1041 AT

+31 88 44 70 000
Mon-Fri 9am-6pm CET


Unify LLC
Sales: Tara Tromp
14425 Falcon Head Blvd.
Building E - Suite 100
Austin, TX 78738

Mon-Fri 9am-6pm CET


Unify LTD
Sales: Joris ter Wolbeek
1-2-20 Kaigan
3/F Shiodome Building
Tokyo, 105-0022

Mon-Fri 9am-6pm CET

Unify is not affiliated with IQVIA or IQVIA's team, nor is it endorsed by or related to IQVIA. Unify is not affiliated with Veeva Systems or Veeva Systems's team, nor is it endorsed by or related to Veeva Systems. Unify is a division of SMIT. Digitaal vakmanschap BV. Crafted in Amsterdam.
© 2024 Unify LLC. All rights reserved
Logo SMIT. Digitaal vakmanschap