id = str_random(40); $token->user_id = $userId; $token->created_at = time(); $token->expires_at = time() + $minutes * 60; return $token; } /** * Get the given token only if it is valid. * * @param string $token * @return static|null */ public static function valid($token) { return static::where('id', $token)->where('expires_at', '>', new DateTime)->first(); } /** * Define the relationship with the owner of this access token. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function user() { return $this->belongsTo('Flarum\Core\Users\User'); } }