Unauthenticated user can't access the page that is under auth middleware, it automatically redirects the user to /login, but you can change this if you want, in app\Exceptions\Handler.php you could overwrite the unauthenticated function
/**
* Convert an authentication exception into a response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
return $request->expectsJson()
? response()->json(['message' => $exception->getMessage()], 401) // <-- YOUR MESSAGE
: redirect()->guest(route('your-route')); // <-- YOUR ROUTE
}
this function is in parent class, and make sure you import this class at the top.
use Illuminate\Auth\AuthenticationException;