public function run() { //$faker = Faker::create(); foreach (range(1001, 9998) as $index) { if ($index == 1111 || $index == 2222 || $index == 3333 || $index == 4444 || $index == 5555 || $index == 6666 || $index == 7777 || $index == 8888) { continue; } CustomerGeneration::create(['customer_no' => $index, 'used' => 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'); }