Skip to content
Bruno Gaspar edited this page Jun 8, 2017 · 6 revisions

Extending Sentinel is extremely easy and straightforward.

You can extend almost anything, but i'll be showing on how to change the User model, but following this should work for most of the stuff on Sentinel.

Step 1

Create a new User model and save it somewhere on your application, just make sure that this model extends Cartalyst\Sentinel\Users\EloquentUser, here's how it might look like:

namespace App;

class User extends \Cartalyst\Sentinel\Users\EloquentUser
{
}

You can add all the necessary methods to this model now.

Step 2

Now we need to register this new model with Sentinel.

You have 2 ways to tell Sentinel to use your new model, through the config file or through runtime, i'll show you both.

Through the Config file

In order to do this, we need to have the Sentinel configuration file published, since we have a version for Laravel 4 and Laravel 5, i'll have both ways belows.

Laravel 4

Run the following php artisan config:publish cartalyst/sentinel on your terminal.

Config file path: app/config/packages/cartalyst/sentinel/config.php

Laravel 5

Run the following php artisan vendor:publish --provider="Cartalyst\Sentinel\Laravel\SentinelServiceProvider" on your terminal.

Config file path: config/cartalyst.sentinel.php

Now open the configuration file with one of the above paths and update the model value on the users array to something like:

'users' => [
    'model' => 'App\User',
],

Note: Our model is using a namespace, make sure you include it!

Runtime

This can be done almost anywhere on your application, either on the routes file, a custom service provider (recommended), etc..

The usage is simple, just call:

Sentinel::getUserRepository()->setModel('App\User');
Sentinel::getPersistenceRepository()->setUsersModel('App\User');

Thats it.


Now whenever you call Sentinel::getUser() it will return your model :)

Clone this wiki locally