public function update($id) { // save updated $record = $this->records->find($id); if (!$record) { Color::create(Input::all()); return $this->respond($record); } $record->fill(Input::all())->save(); return $this->respond($record); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $validator = \Validator::make($request->all(), ['name' => 'required', 'image' => 'image|max:3000|required']); if ($validator->fails()) { return redirect()->route('Colors::create')->withErrors($validator)->withInput()->with('error', '¡Ops! Algo ha salido mal, por favor atiende a los siguientes mensajes:'); } if ($request->hasFile('image')) { $img = $request->file('image'); $ext = $img->getClientOriginalExtension(); $image_name = "color" . str_random(16) . "." . $ext; $category = Color::create(['name' => $request->input('name'), 'image' => $image_name, 'user_id' => Auth::id()]); $category->code = 'C' . str_pad($category->id, 3, "0", STR_PAD_LEFT); $category->save(); Image::make($img)->fit(60, 60)->save($this->admin_content_path() . $this->color_path . $image_name, 100); Image::make($img)->fit(60, 60)->save($this->app_content_path() . $this->color_path . $image_name, 100); } return redirect()->route('Colors::create')->with('status', '¡El nuevo color se ha agregado exitosamente!'); }
/** * Updates existing project in database * * @param Project $project * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function update(Project $project, Request $request) { if (Gate::denies('update-project', $project)) { abort(403); } $data = $request->all(); if ($data['_type'] == 'color') { Color::create($data); } $project->update($data); return redirect()->action('ProjectController@edit', $project->id); }