<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Support\Facades\Route; // Add this line

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string|null
     */
     /*
    protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('login');
        }
    }*/
    
        protected function redirectTo($request)
        {
            if (! $request->expectsJson()) {
                // Get the current route's middleware
                $routeMiddleware = Route::current()->middleware();

                // Check for a specific guard in the middleware array
                if (in_array('auth:member', $routeMiddleware)) {
                    return route('member.login'); // Redirect to admin login
                }
                // Add more conditions for other guards as needed

                return route('login'); // Default login route if no specific guard is found
            }
        }
        
}
