}).then(response => {
if (response.status === 500 ){
alert(error.response.data.message);
}
else {
window.location.replace("/admin/users/"+this.user.id);
}
3 Réponses :
Modifiez votre réponse comme suit:
return response(['message' => "That's less than 6, not allowed"], 500);
Partmètres pour l'aide de la réponse sont Si vous ne retournez pas l'usage JSON
Pour plus d'informations Voir la documentation https://laravel.com/docs /7.x/helpers#method-response P> Réponse (String Message, int Status_Code, Array? En-têtes) CODE> P>
Réponse de retour () -> JSON (Array JSON, INT Statut_code, Array? En-têtes) CODE> P>
Comment je gère Axios est ci-dessous
Pour d'abord, retournez votre réponse de Laravel comme ceci. (Inclure le code d'état) em> Après cela sur votre côté Axios, obtenez le message comme celui-ci p> axios.post().then(function(response){
// this will run if the status code is 200 in laravel response
// Get passed data like 'response.data.message', You will get your passed values after 'response.data'
}).catch(function(error){
notify('error', error.response.data.message); // You will get your passed values after 'error.response.data'
})