1 month ago

JSON Exception is taking to Login Page but need to show the errors in Modal

Posted 1 month ago by nafeeur10

I am using Laravel and Vuejs. I want to Store Data in Database. I am validating my data like this:

try {
            $this->validate($request, [
                'customer_name' => 'required'
            return response()->json([
                'status' => 'success',
                'msg'    => 'Okay',
            ], 200);
        catch(ValidationException $exception) {
            return response()->json([
                'status' => 'error',
                'msg'    => 'Error',
                'errors' => $exception->errors(),
            ], 422);

Exception is giving Correctly. But it's taking me to login page!!

Axios Request to do the action:

saveCustomerInDB(customer) {'/api/data/user/storeCustomer', 
          customer_name: customer.customer_name

        }).then( (response) => {
        }).catch( (error) => {
            console.log("Error", error);

I just want to show the error. Not any redirection. How will I do that??

Please sign in or create an account to participate in this conversation.