対応したときのソース
app\Http\Middleware\Authenticate.php
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Support\Facades\Auth;
class Authenticate extends Middleware
{
protected function unauthenticated($request, array $guards)
{
throw new AuthenticationException(
'Unauthenticated.', $guards, $this->redirectToByGuards($request, $guards)
);
}
/**
* Get the path the user should be redirected to when they are not authenticated.
*/
protected function redirectToByGuards($request, $guards) {
if (!$request->expectsJson()) {
foreach ($guards as $guard) {
if ($guard === 'admin') {
// guardごとに設定
return route('admin.login');
} else {
// 初期設定と同じ
return route('login');
}
}
}
}
}
参考サイト