How to add information about user ID from database to token while login?

Hey. I would like to secure my routes using JWT. At this moment token is created like that:

class GenerateTokenController implements SecretKeyInterface
public static function generateToken($email)
$now = time();
$future = strtotime(’+1 hour’,$now);
$secretKey = self::JWT_SECRET_KEY;

    $payload = [
    return JWT::encode($payload,$secretKey,"HS256");


I would like to add to my token information about user ID which will be taken from Database but I’m new in PHP and don’t know how to do that.

Could anyone explain me that?

Thank you in advance!

Hey @Rashu welcome to the wonderful world of PHP. Judging by your question it sounds to me like you are new to PHP and need to learn how one can interface with the database in order to store and retrieve data? I would recommend reading these tutorials, (at least up to and including section 3). It is by no means the only way to store and retrieve data from a database, but it is a very common/popular method. Also, it is generic and not framework-specific. Other frameworks such as Laravel, have their own framework specific way of interfacing with the database.