laravel/sentinel
Laravel Sentinel provides a simple, lightweight way to build and manage API health/status endpoints in Laravel. Define checks, aggregate results, and expose a consistent response for monitoring systems and uptime tools, with easy configuration and extensible check classes.
Installation:
composer require laravel/sentinel
php artisan sentinel:install
config/sentinel.php, database/migrations/, and resources/views/vendor/sentinel/.Database Migration:
php artisan migrate
users, roles, permissions, throttle, and reminders.First Use Case:
use Cartalyst\Sentinel\Sentinel;
$credentials = ['email' => 'user@example.com', 'password' => 'password'];
$user = Sentinel::authenticate($credentials);
use Cartalyst\Sentinel\Checkpoints\ThrottlingCheckpoint;
use Cartalyst\Sentinel\Checkpoints\RoleCheckpoint;
public function handle($request, Closure $next)
{
Sentinel::check()->role('admin')->throttle()->pass();
return $next($request);
}
Key Config:
config/sentinel.php for:
reminder (password reset settings).throttling (failed login attempts).password (strength requirements).$user = Sentinel::authenticateAndRemember($credentials);
Sentinel::logout();
$user = Sentinel::authenticate($credentials, true); // Persistent cookie
$user->roles()->attach($roleId);
if (Sentinel::check()->role('admin')->pass()) {
// Admin-only logic
}
$user = Sentinel::getUser();
if ($user->hasRole('editor') || $user->hasRole('admin')) {
// Allow access
}
$permission = Sentinel::getRepository('permission')->create(['name' => 'edit_articles']);
$user->permissions()->attach($permission);
if (Sentinel::check()->permission('edit_articles')->pass()) {
// Allow edit
}
// Config: config/sentinel.php
'throttling' => [
'max_attempts' => 5,
'lockout_time' => 15, // minutes
],
Sentinel::check()->throttle()->pass();
$user = Sentinel::findByCredentials(['email' => 'user@example.com']);
Sentinel::reminder()->send($user);
resources/views/vendor/sentinel/reminder.blade.php.use Hybrid_Auth\HybridAuth;
$hybridauth = new HybridAuth(config('hybridauth'));
$adapter = $hybridauth->authenticate('Google');
$userProfile = $adapter->getUserProfile();
$user = Sentinel::findByCredentials(['email' => $userProfile->email]);
if (!$user) {
$user = Sentinel::registerAndActivate($userProfile->email, $password);
}
Sentinel::login($user);
use Laravel\Sanctum\PersonalAccessToken;
$user = Sentinel::getUser();
$token = PersonalAccessToken::createToken($user);
auth middleware with auth:sentinel in app/Http/Kernel.php:
'auth:sentinel' => \Cartalyst\Sentinel\Middleware\Authenticate::class,
Route::get('/admin', function () {
// ...
})->middleware(['auth:sentinel', 'role:admin']);
// EventServiceProvider
protected $listen = [
'auth.attempting' => ['App\Listeners\LogLoginAttempt'],
'auth.failed' => ['App\Listeners\AlertOnFailedLogin'],
];
use Cartalyst\Sentinel\Testing\SentinelTestCase;
class UserTest extends SentinelTestCase
{
public function testAdminAccess()
{
$admin = Sentinel::findByCredentials(['email' => 'admin@example.com']);
$this->actingAs($admin, 'sentinel');
$this->visit('/admin')->see('Dashboard');
}
}
php artisan sentinel:roles
php artisan sentinel:permissions
Schema Conflicts:
users table with custom fields may clash with Sentinel’s schema.User model or use a custom driver:
class User extends \Cartalyst\Sentinel\Users\Eloquent\UserModel
{
protected $table = 'custom_users';
}
Session Driver Mismatch:
file session driver, which may not scale.session.driver in .env (e.g., redis) and ensure Sentinel’s remember cookie uses the same driver.Throttling Database Locks:
'throttling' => [
'driver' => 'redis',
],
HybridAuth Deprecation:
hybridauth/hybridauth is unmaintained; social auth requires custom OAuth logic.Legacy cartalyst/sentinel Migration:
Sentinel::getUser()) may behave differently.Permission Caching:
hasRole()/hasPermission() checks can bloat queries.public function getRolesAttribute()
{
return $this->roles()->pluck('name')->toArray();
}
Password Reset Token Expiry:
config/sentinel.php:
'reminder' => [
'expire' => 30, // minutes
],
Middleware Order:
auth:sentinel must run before role/permission middleware.Kernel.php:
$middlewareGroups['web'] = [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// Sentinel middleware must come after session starts
\Cartalyst\Sentinel\Middleware\Authenticate::class,
\App\Http\Middleware\CheckForRoles::class,
];
Enable Sentinel Logging:
'logging' => [
'enabled' => true,
'path' => storage_path('logs/sentinel.log'),
],
Check Throttle Status:
$throttle = Sentinel::getThrottle();
dd($throttle->getAttempts(), $throttle->isLocked());
Inspect Failed Logins:
php artisan sentinel:throttle-list
Verify User Roles/Permissions:
dd(Sentinel::getUser()->roles, Sentinel::getUser()->permissions);
How can I help you explore Laravel packages today?