You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
734 B
PHP
29 lines
734 B
PHP
<?php
|
|
|
|
namespace App\Exceptions;
|
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|
use Throwable;
|
|
use Illuminate\Auth\AuthenticationException; // <- importante importarlo
|
|
|
|
class Handler extends ExceptionHandler
|
|
{
|
|
// ... otras propiedades y métodos
|
|
|
|
/**
|
|
* Convert an authentication exception into a response.
|
|
*/
|
|
protected function unauthenticated($request, AuthenticationException $exception)
|
|
{
|
|
// Si la petición espera JSON (API)
|
|
if ($request->expectsJson()) {
|
|
return response()->json(['error' => 'No autenticado.'], 401);
|
|
}
|
|
|
|
// Para web (redirección normal)
|
|
return redirect()->guest(route('login'));
|
|
}
|
|
|
|
// ... otros métodos
|
|
}
|