lundi 17 octobre 2016

Code will be execute or stop if validation fail in laravel?

I wanted to know that what will be happen if validation fail in laravel, means that the rest of code will be execute or not. I have following code in store method

$this->validate($request, [
    'name' => 'required|min:3',
    'email' => 'required|email',
    'message' => 'required',
]);

return response()->json([
    'success' => 'Your email has been sent successfully.'
]); 

I have checked with $validator->fails()) but it does not return the error message which i added in the if statement.

if($validator->fails()) {
    return response()->json([
        'error' => 'There are some errors.'
    ]); 
}else{
    return response()->json([
        'success' => 'Your email has been sent successfully.'
    ]); 
}

Can anyone guide me about my question, i would like to appreciate. Thank You



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire