コード例 #1
1
 public function run()
 {
     $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 SOS.xlsx";
     echo (string) $file_path, "\n";
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('store_sos_tags')->truncate();
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $filePath = $file_path;
     $reader->open($filePath);
     // Accessing the sheet name when reading
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Sheet1') {
             $cnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if (!empty($row[0])) {
                     // dd($row);
                     if ($cnt > 0) {
                         // dd($row);
                         $store = Store::where('store_code', $row[0])->first();
                         // dd($store);
                         $category = FormCategory::where('category', strtoupper($row[2]))->first();
                         // dd($category);
                         $sos = SosTagging::where('sos_tag', strtoupper($row[3]))->first();
                         // dd($sos);
                         StoreSosTag::insert(array('store_id' => $store->id, 'form_category_id' => $category->id, 'sos_tag_id' => $sos->id));
                         // echo (string)$row[0], "\n";
                     }
                     $cnt++;
                 }
             }
         } else {
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
コード例 #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     // dd($request->all());
     $this->validate($request, ['store' => 'required|max:100|unique_with:stores, store_code = store_code,' . $id, 'store_code' => 'required', 'distributor' => 'required|not_in:0', 'template' => 'required|not_in:0', 'passing' => 'required|not_in:0']);
     \DB::beginTransaction();
     try {
         $store = Store::findOrFail($id);
         $store->distributor_id = $request->distributor;
         $store->store_code = $request->store_code;
         $store->store = $request->store;
         $store->grade_matrix_id = $request->passing;
         $store->audit_template_id = $request->template;
         $store->update();
         StoreSosTag::where('store_id', $store->id)->delete();
         if (!empty($request->cat)) {
             foreach ($request->cat as $key => $value) {
                 $data[] = ['store_id' => $store->id, 'form_category_id' => $key, 'sos_tag_id' => $value];
             }
             StoreSosTag::insert($data);
         }
         \DB::commit();
         Session::flash('flash_message', 'Store successfully updated!');
         return redirect()->route("store.edit", [$id]);
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }