amit028
3 months ago
500
5
Laravel

Request file validation fails not redirecting to view page in which form is submitting.

Posted 3 months ago by amit028

PROBLEM

I am submitting a form using and for validation i'm using Request file. There i have given validation for email that it should be unique. When i am trying to insert same email it is showing error which is good but i wanted to redirect it back to view. This is my code

CONTROLLER-

public function store_company(RegisterCompany $request) {

}

REQUEST FILE -

namespace App\Http\Requests\Company;

use App\GoogleCaptchaSetting;

use App\Http\Requests\CoreRequest;

use App\Rules\Captcha;

class RegisterCompany extends CoreRequest {

public function rules()
{
    $google_captcha = GoogleCaptchaSetting::first();

    $rules =  [
        'business_name' => 'required',
        'email' => 'required|email',
        'contact' => 'required',
        'address' => 'required',
        'name' => 'required',
        'password' => 'required|min:6'
        ];

        if($google_captcha->status == 'active' && $google_captcha->v2_status == 'active' )
        {
            $rules['g-recaptcha-response'] = new Captcha();
        }

        return $rules;
}

}

ERROR -

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '[email protected]' for key 'users_email_unique' (SQL: insert into users (name, email, password, company_id, updated_at, created_at) values ([email protected], [email protected], $2y$10$odzYOR9Ox7SaB6KEfRFC3ulhbjOSb9.VFh58S1iSbsVaCKVoRRl1q, 106, 2020-07-21 08:37:10, 2020-07-21 08:37:10))

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