veseluy-rodjer / json-web-token
Work with json web tokens
Installs: 1 031
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/veseluy-rodjer/json-web-token
Requires
- php: ^8.0
This package is auto-updated.
Last update: 2025-10-29 01:03:26 UTC
README
Examples:
namespace App\Http\Controllers\Users;
use VeseluyRodjer\JsonWebToken\Services\JsonWebTokenService;
class CustomerController extends Controller { public function __construct( private JsonWebTokenService $jsonWebTokenService ) {}
public function usingPackage(): JsonResponse
{
    $token = $this->jsonWebTokenService->createToken([
        'payload' => [
            'user_email' => request()->email,
            'role_name' => request()->role_name
        ],
        'secret' => config('jwt.secret'),
    ]);
    $dataFromToken = $this->jsonWebTokenService->getDataFromToken($request->token);
}
}
namespace App\Http\Requests\User;
use VeseluyRodjer\JsonWebToken\Services\JsonWebTokenService;
class AdminRequest extends FormRequest { public function __construct( private JsonWebTokenService $jsonWebTokenService ) {}
public function rules()
{
    return [
        'token' => [
            function ($attribute, $value, $fail) {
                if (! $this->jsonWebTokenService->checkToken($value, config('jwt.secret'))) {
                    $fail('The '.$attribute.' is invalid.');
                }
            },
        ],
    ];
}
}