$this->GOOGLE_ReCAPTCHA_KEY, 'user_shop' => Util::getUserShop(), ]; return view('web.templates.kontakt', $data); } public function store() { $user_shop = Util::getUserShop(); $rules = array( 'first_name'=>'required', 'last_name'=>'required', 'email'=>'required|email', 'message'=>'required', 'g-recaptcha-response'=>'required|recaptcha', 'accepted_data_protection' => 'required', ); Validator::extend('recaptcha', function($attribute, $value, $parameters, $validator) { return $this->reCaptcha_validate($attribute, $value, $parameters, $validator); }); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return back()->withErrors($validator)->withErrors($validator)->withInput(Input::all()); }else{ $contact = []; $contact['first_name'] = Input::get('first_name'); $contact['last_name'] = Input::get('last_name'); $contact['email'] = Input::get('email'); $contact['phone'] = Input::get('phone'); $contact['subject'] = Input::get('subject'); $contact['message'] = Input::get('message'); $checkout_mail = config('app.checkout_mail'); if($user_shop){ Mail::to($contact['email'])->bcc([$user_shop->user->email, $checkout_mail])->send(new MailContact($contact)); }else{ Mail::to($contact['email'])->bcc($checkout_mail)->send(new MailContact($contact)); } $data = [ 'user_shop' => Util::getUserShop(), ]; return view('web.templates.contact-final', $data); } } private function reCaptcha_validate($attribute, $value, $parameters, $validator) { $client = new Client(); $response = $client->post( 'https://www.google.com/recaptcha/api/siteverify', ['form_params' => [ 'secret' => $this->GOOGLE_ReCAPTCHA_SECRET, 'response' => $value ] ] ); $body = json_decode((string)$response->getBody()); return $body->success; } }