public function updateConfigure() { if (Input::has('pk')) { if (!Request::ajax()) { return App::abort(404); } return self::updateQuickEdit(); } else { if (Request::ajax()) { $arrReturn = ['status' => 'error']; $configure = new Configure(); $configure->cname = Input::get('cname'); $configure->ckey = Input::get('ckey'); if (Input::hasFile('cvalue')) { $path = app_path('files'); if (!File::exists($path)) { File::makeDirectory($path, 493, true); } $path = str_replace(['\\', '/'], DS, $path); $file = Input::file('cvalue'); $file->move($path, $configure->ckey . '.' . $file->getClientOriginalExtension()); $configure->cvalue = $path . DS . $configure->ckey . '.' . $file->getClientOriginalExtension(); } else { $configure->cvalue = Input::get('cvalue'); } $configure->cdescription = Input::get('cdescription'); $configure->active = Input::has('active') ? 1 : 0; $pass = $configure->valid(); if ($pass) { $configure->save(); $arrReturn = ['status' => 'ok']; $arrReturn['message'] = $configure->cname . ' has been saved'; $arrReturn['data'] = $configure; } else { $arrReturn['message'] = ''; $arrErr = $pass->messages()->all(); foreach ($arrErr as $value) { $arrReturn['message'] .= "{$value}\n"; } } $response = Response::json($arrReturn); $response->header('Content-Type', 'application/json'); return $response; } } $arrPost = Input::all(); unset($arrPost['_token']); foreach ($arrPost as $key => $value) { if (in_array($key, ['main_logo', 'favicon'])) { if (!Input::hasFile($key)) { continue; } if ($key == 'main_logo') { $path = public_path('assets' . DS . 'images' . DS . 'logos'); $width = 400; $name = 'logo'; } else { if ($key == 'favicon') { $path = public_path('assets' . DS . 'images' . DS . 'favicons'); $width = 16; $name = 'favicon'; } } $configure = Configure::firstOrNew(['ckey' => $key]); $configure->ckey = $key; $configure->cname = Str::title(str_replace('_', ' ', $key)); if (!empty($configure->cvalue) && File::exists(public_path($configure->cvalue))) { File::delete(public_path($configure->cvalue)); } $path = VIImage::upload(Input::file($key), $path, $width, false, $name); $path = str_replace(public_path() . DS, '', $path); $configure->cvalue = str_replace(DS, '/', $path); $configure->save(); } else { $configure = Configure::firstOrNew(['ckey' => $key]); $configure->ckey = $key; $configure->cname = Str::title(str_replace('_', ' ', $key)); $configure->cvalue = $value; $configure->save(); if ($key == 'mask') { Cache::tags('images')->flush(); Cache::forever('mask', $value); } } } return Redirect::to(URL . '/admin/configures')->with('flash_success', 'Main Configure has been saved.'); }