/** * Store a newly created resource in storage. * * @return Response */ public function store(Requests\CreateCustomerRequest $response) { // $data = $response->all(); //dd ($data); $customers = new \App\Customer($data); //dd($customers); $customers->save(); return redirect('admin/customer'); }
public function createCustomer(CreateCustomerRequest $request) { // getDataRequest $getDataRequest = $request->all(); $ip = $_SERVER['SERVER_ADDR']; $response = $getDataRequest['g-recaptcha-response']; $list = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=6LdkCQoTAAAAAHt8GyYu3DzOO-5ngXRKMWm8HE1A&response=' . $response . '&remoteip=' . $ip); $json = json_decode($list, true); // check capcha if ($json['success'] == 1) { $user = new User(); $customer = new Customer(); $customer = autoAssignDataToProperty($customer, $getDataRequest); $user = autoAssignDataToProperty($user, $getDataRequest); $user->avatar = 'person.png'; $this->doRegister($user); $remember_token = str_random(30); $key_active = str_random(30); $name = $user->name; $password = $user->password; $email = $user->email; $data = ['name' => $name, 'email' => $email]; $user->remember_token = $remember_token; $user->created_at = Carbon::now(); $user->password = md5($user->password . md5($remember_token)); $user->key_active = $key_active; //check add new DB::beginTransaction(); try { $user->save(); $user_Id = User::where('email', $email)->first()->id; $customer->user_id = $user_Id; $customer->save(); DB::commit(); Mail::send('auth.mail_welcome', ['name' => $data['name'], 'key' => $key_active, 'password' => $password], function ($message) use($data) { $message->to($data['email'], $data['name'])->from('*****@*****.**')->subject('Welcome to the TopMp3!'); }); return redirect_success('AuthController@getLogin', 'Check your email ' . $data['email'] . ' to active!'); } catch (\Exception $e) { dd($e); DB::rollback(); return redirect_errors('Have Error, Try again,please!'); } } else { return redirect_errors('Wrong reCapcha!'); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(CreateCustomerRequest $request) { Customers::create($request->all()); return redirect('customer'); }