コード例 #1
0
 public function update($id)
 {
     try {
         $product = Product::findOrFail($id);
         $img = Input::File('img');
         $description = Input::get('description');
         strip_tags($img);
         $rules = ['img' => 'mimes:jpg,jpeg,png,gif', 'description' => 'max:80'];
         $messages = array('mimes' => '¡Atención! Solo están permitidas imágenes en: jpg, png o gif.', 'max' => '¡Atención! Máximo :max caracteres de descripción');
         $validator = \Validator::make(['img' => $img, 'description' => $description], $rules, $messages);
         if ($validator->passes()) {
             if ($img) {
                 $filename = str_random(10) . '.' . $img->getClientOriginalName();
                 $destinationPath = public_path() . '/uploads/products/';
                 $uploadSuccess = $img->move($destinationPath, $filename);
                 $product->img = $filename;
             } else {
                 $product->img = $product['img'];
             }
             $product->name = Input::get('name');
             $product->description = Input::get('description');
             $product->price = Input::get('price');
             $product->updated_at = new DateTime();
             $product->update(['id']);
             return Redirect::route('products')->with('error', false)->with('msg', 'Producto actualizada con éxito.')->with('class', 'info');
         } else {
             return Redirect::back()->withErrors($validator);
         }
     } catch (Exception $exc) {
         echo $exc->getMessage() . " " . $exc->getLine();
         return Redirect::back()->with('error', true)->with('msg', '¡Algo salió mal! Contacte con administrador.')->with('class', 'danger');
     }
 }
コード例 #2
0
ファイル: LabController.php プロジェクト: ramant15/ektimo
 public function lab_upload($id)
 {
     $user = \Auth::user();
     $userId = $user->id;
     if ($id) {
         $job = DB::table('work_schedule.events')->join('work_schedule.calendars', 'work_schedule.events.calendar_id', '=', 'work_schedule.calendars.calendar_id')->where('work_schedule.events.order_id', '=', $id)->first();
         $file_path = base_path() . '/storage/excel/' . $id;
         if (File::exists($file_path)) {
             $job_file = 'exist';
         } else {
             $job_file = '';
         }
         $detail = Order::with('details')->join('site_details', 'site_details.id', '=', 'orders.site_id')->where('orders.id', '=', $id)->first();
         foreach ($detail['details'] as $value) {
             $test_material[] = DB::table('test_processes')->join('process_items', 'test_processes.item_id', '=', 'process_items.id')->select('process_items.name', 'process_items.image', 'process_items.type')->where('test_id', '=', $value['test_id'])->get();
         }
         $documents = array();
         foreach ($detail['details'] as $item) {
             $test_id = $item['test_id'];
             // $path = public_path().'/TestFiles/'.$userId."/".$id;
             $path = public_path() . '/TestFiles/' . $id;
             //$main_path = public_path().'/TestFiles/'.$userId."/".$id;
             // $half_path = public_path().'/TestFiles/'.$userId;
             if (File::exists($path)) {
                 $uploaded_file = \Input::File('test_files');
                 if ($uploaded_file) {
                     $fileName = $uploaded_file->getClientOriginalName();
                     $uploaded_file->move($path, $fileName);
                     // read uploaded file //
                     Excel::load($path . '/' . $fileName, function ($reader) {
                         // Getting all results
                         $results = $reader->toArray();
                     });
                 }
                 //Session::flash('flash_type', 'alert-success');
                 //Session::flash('flash_message', 'File uploaded successfully.');
                 $files = File::allFiles($path);
                 if (!empty($files)) {
                     foreach ($files as $file) {
                         $documents[] = array('name' => $file->getfileName(), 'path' => $file->getpathName());
                     }
                 }
             }
         }
     }
     $items = DB::table('users')->select('id', 'name')->where('type', '=', 'laboratory')->get();
     return view('lab/lab_detail')->with(compact('job', 'detail', 'documents', 'job_file', 'test_material', 'items'));
 }
コード例 #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     //         1. setting validasi
     $messages = array('required' => 'Inputan <b>Tidak Boleh Kosong</b>!', 'numeric' => 'Inputan <b>Harus Angka</b>!', 'same' => 'Password <b>Tidak Sama</b>!');
     $validator = Validator::make(Input::all(), array("nama" => "required", "usernm" => "required", "norek1" => "required|numeric", "norek2" => "required|numeric", "ttl" => "required", "tglaktif" => "required", "addr1" => "required", "notelp" => "required|numeric", "kmindv" => "required|numeric", "kmtim" => "required|numeric"), $messages);
     // 2a. jika semua validasi terpenuhi simpan ke database
     if ($validator->passes()) {
         $karyawan = mk01::find($id);
         if (Input::hasFile('foto')) {
             if (Input::File('foto')->isValid()) {
                 $img = Input::File('foto');
                 $destinationPath = 'uploads';
                 $filename = rand(10000, 99999) . "_" . $img->getClientOriginalName();
                 //                $fullname = rand(10000, 99999) . '_' . $filename . '.' . $img->getClientOriginalExtension();
                 $img->move($destinationPath, $filename);
             } else {
                 Session::flash('mk01_failed', 'Foto tidak valid!');
                 return Redirect::to('master/karyawan/create');
             }
         } else {
             $filename = $karyawan->pic;
         }
         $karyawan->nama = Input::get('nama');
         $karyawan->usernm = Input::get('usernm');
         $karyawan->email = Input::get('email');
         $karyawan->gndr = Input::get('gndr');
         $karyawan->norek1 = Input::get('norek1');
         $karyawan->norek2 = Input::get('norek2');
         $karyawan->tglaktif = strftime("%Y-%m-%d", strtotime(Input::get('tglaktif')));
         $karyawan->ttl = strftime("%Y-%m-%d", strtotime(Input::get('ttl')));
         $karyawan->addr1 = Input::get('addr1');
         $karyawan->notelp = Input::get('notelp');
         $karyawan->status = "Y";
         $karyawan->pic = $filename;
         $karyawan->tbsld = 0;
         $karyawan->htsld = 0;
         $karyawan->idjb = Input::get('idjb');
         $karyawan->kmindv = Input::get('kmindv');
         $karyawan->kmtim = Input::get('kmtim');
         $karyawan->save();
         $datas = $karyawan->mj03;
         $datas[0]->mj02_id = Input::get('idjk1');
         $datas[0]->save();
         $datas[1]->mj02_id = Input::get('idjk2');
         $datas[1]->save();
         Session::flash('mk01_success', 'Data Telah Diubah!');
         return Redirect::to('master/karyawan');
     } else {
         return Redirect::to('master/karyawan/edit/' . $id)->withErrors($validator)->withInput();
     }
 }