My laravel returns a 404 when it doesn’t find the user in the bank. I remember that there is a way to do this check and return a response, but I don’t remember and I can’t find it. Can anyone help me?
I’m not going to put the entire function code
Route::post('/users/validate-pin/{user}', [AppHttpControllersApiUserController::class, 'validatePIN'])->name('api-users.validatePIN');
public function validatePIN(User $user, Request $request)
{
try {
if(!$request->user()->can('Validar PIN')){
return response()->json([
'success' => false,
'message' => 'Não autorizado',
'error' => 'Unauthenticated',
], 401);
}
...
} catch (Throwable $error) {
dd($error);
return response()->json([
'success' => false,
'message' => 'Erro no sistema',
'error' => $error,
], 500);
}
}