public function doCreate(CreateAreaRequest $request) { $area = new Area(); $area->name = $request->name; try { $area->save(); return redirect()->back()->with('message', 'Area has been added successfully !'); } catch (ParseException $ex) { echo 'Failed to create new meal , with error message: ' . $ex->getMessage(); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['name' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors($validator); } //add new area $area = new Area(); $area->name = $request->input('name'); $area->save(); return redirect()->back()->withSuccess('area toegevoegd'); }
public function postRegister(Request $request) { $validator = Validator::make($request->all(), ['nombre' => 'required|max:30', 'responsable' => 'required|max:30']); if ($validator->fails()) { return redirect('area/registrar')->withInput()->withErrors($validator); } $area = new Area(); $area->nombre = $request->nombre; $area->descripcion = $request->descripcion; $area->responsable = $request->responsable; $area->save(); return redirect('area/registrar'); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $this->validate($request, ['area' => 'required|max:100|unique_with:areas, customer = customer_id', 'customer' => 'required|not_in:0']); \DB::beginTransaction(); try { $area = new Area(); $area->customer_id = $request->customer; $area->area = $request->area; $area->save(); \DB::commit(); Session::flash('flash_message', 'Area successfully added!'); return redirect()->route("area.index"); } catch (Exception $e) { DB::rollBack(); return redirect()->back(); } }
public function run() { $start_date = ''; $end_date = ''; $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $value); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $file_path = $folderpath . "/" . $latest . "/Store Mapping.xlsx"; echo (string) $file_path, "\n"; // dd($file_path); Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('audit_templates')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->template)) { $template = AuditTemplate::where('template', $row->template)->first(); if (count($template) == 0) { $newtemplate = new AuditTemplate(); $newtemplate->template_code = $row->channel_code; $newtemplate->template = $row->template; $newtemplate->save(); } } }); }); DB::table('grade_matrixs')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->enrollment_type)) { $matrix = GradeMatrix::where('desc', $row->enrollment_type)->first(); if (count($matrix) == 0) { $newmatrix = new GradeMatrix(); $newmatrix->desc = $row->enrollment_type; $newmatrix->save(); } } }); }); DB::table('users')->truncate(); DB::table('role_user')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->fullname)) { $userlist = explode("/", $row->fullname); $emaillist = explode("/", $row->email); // dd($row); for ($i = 0; $i < count($userlist); $i++) { $user = User::where('username', $row->username)->first(); if (count($user) == 0) { if (empty($emaillist[$i])) { $email = strtolower($row->username . "@unilever.com"); } else { $email = strtolower($emaillist[$i]); } $newuser = User::create(array('name' => strtoupper($userlist[$i]), 'email' => $email, 'username' => $row->username, 'password' => Hash::make('password'))); $newuser->roles()->attach(3); } else { // $user->name = strtoupper($row->fullname); // $user->username = $row->username; // $user->email = strtolower($row->email); // $user->update(); // if(!$user->hasRole('field')){ // $user->roles()->attach(3); // } // echo $user->hasRole('field'); } } } }); }); DB::table('accounts')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $account = Account::where('account', $row->account)->first(); if (count($account) == 0) { $newaccount = new Account(); $newaccount->account = $row->account; $newaccount->save(); } } }); }); DB::table('customers')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { // var_dump($row); $account = Account::where('account', $row->account)->first(); if (!empty($account)) { $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first(); if (count($customer) == 0) { $newcustomer = new Customer(); $newcustomer->account_id = $account->id; $newcustomer->customer_code = $row->customer_code; $newcustomer->customer = $row->customer; $newcustomer->save(); } } } }); }); DB::table('areas')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $account = Account::where('account', $row->account)->first(); if (!empty($account)) { $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first(); if (!empty($customer)) { $area = Area::where('customer_id', $customer->id)->where('area', $row->area)->first(); if (count($area) == 0) { $newarea = new Area(); $newarea->customer_id = $customer->id; $newarea->area = $row->area; $newarea->save(); } } } } }); }); DB::table('regions')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $region = Region::where('region_code', $row->region_code)->where('region', $row->region)->first(); if (count($region) == 0) { $newregion = new Region(); $newregion->region_code = $row->region_code; $newregion->region = $row->region; $newregion->save(); } } }); }); DB::table('distributors')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $dis = Distributor::where('distributor_code', $row->distributor_code)->where('distributor', $row->distributor)->first(); if (count($dis) == 0) { $newdis = new Distributor(); $newdis->distributor_code = $row->distributor_code; $newdis->distributor = strtoupper($row->distributor); $newdis->save(); } } }); }); DB::table('stores')->truncate(); DB::table('store_user')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $account = Account::where('account', $row->account)->first(); if (!empty($account)) { $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first(); if (!empty($customer)) { $region = Region::where('region_code', $row->region_code)->first(); $dis = Distributor::where('distributor_code', $row->distributor_code)->first(); $store = Store::where('account_id', $account->id)->where('customer_id', $customer->id)->where('region_id', $region->id)->where('distributor_id', $dis->id)->where('store_code', $row->store_code)->where('store', $row->store_name)->first(); if (count($store) == 0) { $template = AuditTemplate::where('template', $row->template)->first(); $matrix = GradeMatrix::where('desc', $row->enrollment_type)->first(); $newstore = new Store(); $newstore->account_id = $account->id; $newstore->customer_id = $customer->id; $newstore->region_id = $region->id; $newstore->distributor_id = $dis->id; $newstore->store_code = $row->store_code; $newstore->store = $row->store_name; $newstore->grade_matrix_id = $matrix->id; $newstore->audit_template_id = $template->id; $newstore->save(); $emaillist = explode("/", $row->email); for ($i = 0; $i < count($emaillist); $i++) { if (empty($emaillist[$i])) { $email = strtolower($row->username . "@unilever.com"); } else { $email = strtolower($emaillist[$i]); } $user = User::where('email', $email)->first(); $newstore->users()->attach($user->id); } } else { $emaillist = explode("/", $row->email); for ($i = 0; $i < count($emaillist); $i++) { if (empty($emaillist[$i])) { $email = strtolower($row->username . "@unilever.com"); } else { $email = strtolower($emaillist[$i]); } $user = User::where('email', $email)->first(); $store->users()->attach($user->id); } } } } } }); }); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
/** * 区域保存处理 */ public function areaStore() { // 新建区域实例 $objArea = new Area(); // TODO 存在检查 // $objArea->name_jp = Input::get('name_jp'); // $objArea->name_en = Input::get('name_en'); $objArea->name_cn = Input::get('name_cn'); $objArea->name_jp = Input::get('name_cn'); $objArea->name_en = Input::get('name_cn'); // $objArea->desc_jp = Input::get('desc_jp'); // $objArea->desc_en = Input::get('desc_en'); $objArea->desc_cn = Input::get('desc_cn'); $objArea->desc_jp = Input::get('desc_cn'); $objArea->desc_en = Input::get('desc_cn'); $objArea->need_area_id = Input::get('need_area_id'); $objArea->type = Input::get('type'); $objArea->status = Input::get('status'); $objArea->start_datetime = Input::get('start_datetime', Carbon::now()); $objArea->end_datetime = Input::get('end_datetime', Carbon::now()); if ($objArea->save()) { return Redirect::to('admin/dungeon/area'); } else { return Redirect::back()->withInput()->withErrors('保存失败!'); } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $area = new Area(); $area->save(); return redirect()->route('areas.index')->with('message', 'Item created successfully.'); }