'datetime', ]; /** * 토큰 만료 시간 (분) */ public const EXPIRES_IN_MINUTES = 5; /** * 사용자 관계 */ public function user(): BelongsTo { return $this->belongsTo(User::class); } /** * 새 토큰 생성 */ public static function createForUser(int $userId): self { // 기존 토큰 삭제 (해당 사용자) self::where('user_id', $userId)->delete(); return self::create([ 'user_id' => $userId, 'token' => Str::random(64), 'expires_at' => now()->addMinutes(self::EXPIRES_IN_MINUTES), ]); } /** * SAM 사이트 자동 로그인 URL 생성 * APP_ENV 기반 도메인 매핑 */ public function getAutoLoginUrl(): string { $env = config('app.env'); if ($env === 'production') { $baseUrl = 'https://stage.sam.it.kr'; } else { // local, DEV 등: 현재 호스트의 서브도메인을 dev로 변경 $scheme = request()->getScheme(); $host = request()->getHost(); $devHost = preg_replace('/^[^.]+\./', 'dev.', $host); $baseUrl = "{$scheme}://{$devHost}"; } return "{$baseUrl}/auto-login?token={$this->token}"; } }