1. Go to this page and download the library: Download chantouch/laravel-jwt-redis library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
return [
/*
|--------------------------------------------------------------------------
| Your User Model
|--------------------------------------------------------------------------
|
| You can set specific user model.
|
*/
'user_model' => \App\Models\User::class,
];
return [
/*
|--------------------------------------------------------------------------
| JWTRedis User Model Observer
|--------------------------------------------------------------------------
|
| This observer class, listening to all events on your user model. Is triggered
| when you assign roles & permissions to user, or update and delete to
| your user model.
|
*/
'observer' => Chantouch\JWTRedis\Observers\UserRedisObserver::class,
];
return [
/*
|--------------------------------------------------------------------------
| Observer Events Are Queued
|--------------------------------------------------------------------------
|
| If this option is true, model's events are processed as a job on queue.
|
| * ~ Remember to run Queue Worker if this option is true. ~ *
|
*/
'observer_events_queue' => true,
];
return [
/*
|--------------------------------------------------------------------------
| Cache on Redis up to jwt_ttl value.
|--------------------------------------------------------------------------
|
| If it's option is true, user stored in Redis up to jwt_ttl value time.
|
*/
'redis_ttl_jwt' => true,
/*
|--------------------------------------------------------------------------
| Cache on Redis up to specific time
|--------------------------------------------------------------------------
|
| If you don't want to store user in Redis until JWT expire time,
| you can set this value as minute.
|
*/
'redis_ttl' => 60,
];
return [
/*
|--------------------------------------------------------------------------
| Cache Prefix
|--------------------------------------------------------------------------
|
| If it's user id is 1, this user stored in Redis as auth_1.
|
*/
'redis_auth_prefix' => 'auth_',
];
return [
/*
|--------------------------------------------------------------------------
| Banned User Checking
|--------------------------------------------------------------------------
|
| If the check_banned_user option is true, that users cannot access
| the application.
|
*/
'check_banned_user' => false,
/*
|--------------------------------------------------------------------------
| Status Column For Banned User Checking
|--------------------------------------------------------------------------
|
| You can set your specific column name of your user model.
|
*/
'status_column_title' => 'status',
/*
|--------------------------------------------------------------------------
| Restricted statuses For Banned User Checking
|--------------------------------------------------------------------------
|
| If the user has one of these statuses and trying to reach your application,
| JWTRedis throws AccountBlockedException.
| You can set the message (check it an error array) that will return in this
| exception.
|
*/
'banned_statuses' => [
'banned',
'deactivate'
],
];
return [
/*
|--------------------------------------------------------------------------
| Cache This Relations When a User Has Authenticated
|--------------------------------------------------------------------------
|
| You can add this array to your own relations, anything you want to store
| in Redis. We recommend caching only roles and permissions here as much as
| possible.
|
*/
'cache_relations' => [
'roles.permissions',
'permissions'
],
];
return [
/*
|--------------------------------------------------------------------------
| Customize All Exception Messages and Codes
|--------------------------------------------------------------------------
|
| You can customize error code,message, title for your application.
|
*/
'errors' => [
'TokenNotProvidedException' => [
'title' => 'Your custom title',
'message' => 'Your custom error message.',
'code' => 99999
]
],
];