Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     //$this->validate($request, ['name' => 'required']); // Uncomment and modify if needed.
     $color = Color::findOrFail($id);
     $update = $request->all();
     // is new image uploaded?
     if ($file = Input::file('image')) {
         $fileName = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension() ?: 'png';
         $folderName = '/uploads/';
         $destinationPath = Config::get('app.path') . $folderName;
         $safeName = time() . "_" . str_random(10) . '.' . $extension;
         $file->move($destinationPath, $safeName);
         //delete old pic if exists
         if (File::exists(Config::get('app.path') . $color->image)) {
             File::delete(Config::get('app.path') . $color->image);
         }
         $update['image'] = $safeName ? $folderName . $safeName : '';
     }
     if (isset(Color::$boolean)) {
         foreach (Color::$boolean as $field) {
             if (isset($update[$field]) && $update[$field] == "on") {
                 $update[$field] = 1;
             } else {
                 $update[$field] = 0;
             }
         }
     }
     $color->update($update);
     return redirect('admin/colors')->with('success', Lang::get('message.success.update'));
 }
 public function guardarTraduccion($request, $id)
 {
     $color = Color::findOrFail($id);
     $color->name = $request->input('name');
     $color->save();
     $languages = Language::get();
     foreach ($languages as $lang) {
         $nameLang = $request->input('name' . $lang->id);
         if (trim($nameLang) != "") {
             $languages_colors = LanguageColor::where('id_language', $lang->id)->where('id_color', $color->id)->first();
             if (!isset($languages_colors->id)) {
                 $languages_colors = new LanguageColor();
             }
             $languages_colors->id_language = $lang->id;
             $languages_colors->id_color = $color->id;
             $languages_colors->name = $nameLang;
             $languages_colors->save();
         } else {
             $languages_colors = LanguageColor::where('id_language', $lang->id)->where('id_color', $color->id)->first();
             if (isset($languages_colors->id)) {
                 $languages_colors->delete();
             }
         }
     }
 }
Example #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     $color = Color::findOrFail($id);
     $auxName = $color->name;
     if (File::exists($this->admin_content_path() . $this->color_path . $color->image) && File::exists($this->app_content_path() . $this->color_path . $color->image)) {
         File::delete($this->admin_content_path() . $this->color_path . $color->image);
         File::delete($this->app_content_path() . $this->color_path . $color->image);
     }
     $color->delete();
     return redirect()->route('Colors::index')->with('status', 'Color ' . $auxName . ' eliminado correctamente');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $color = Color::findOrFail($id);
     $color->delete();
     return redirect()->route('admin.color.index')->with('alert-success', 'Delete complete');
 }