Ejemplo n.º 1
0
 /**
  * Store a newly created customer in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Customer::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $customer_no = CustomerGeneration::where('used', 0)->orderBy(DB::raw('RAND()'))->first();
     $data['username'] = '';
     $data['password'] = '';
     $data['short_name'] = '';
     $data['customer_no'] = $customer_no->customer_no;
     $data['telephone'] = '';
     $data['url'] = '';
     $data['postcode'] = '';
     $data['business'] = '';
     $customer = Customer::create($data);
     $customergeneration = CustomerGeneration::find($customer_no->id);
     $customergeneration->used = 1;
     $customergeneration->save();
     CustomerReceivedAddress::create(['customer_id' => $customer->id, 'name' => $customer->name, 'mobile' => $customer->mobile, 'province' => 0, 'city' => 0, 'district' => 0, 'street' => '', 'address' => $customer->address, 'postcode' => '', 'default' => 1]);
     return Redirect::route('admin.customers.index');
 }