belongsTo(User::class); } public static function existsToken(User $user, string $type) { $userId = $user->id; $token = self::where('user_id', $userId) ->where('type', 'email_verification') ->where('created_at', '>=', Carbon::now()->subDay()) ->first(); return $token; } public static function existsTokenByToken(string $token, string $type) { $token = self::where('token', $token) ->where('type', $type) ->where('created_at', '>=', Carbon::now()->subDay()) ->first(); return $token; } public static function createToken(User $user, string $type) { return self::create([ 'user_id' => $user->id, 'token' => Str::random(64), 'type' => $type, 'created_at' => now(), ]); } }