public function update(News $news, Request $request) { //dd($request->all()); $user = $this->user; $this->validate($request, ['title' => 'required', 'content' => 'required', 'status' => 'required | in:0,1']); if ($request->hasFile('image')) { $this->validate($request, ['image' => 'mimes:jpeg,jpg,png,bmp,gif | max:1024']); $imageName = $this->uploadImage($request->file('image')); // delete the last image if exist $path = public_path('images/news/') . '/' . $news->image; if (File::exists($path)) { File::delete($path); } } else { $imageName = $news->image; //old image name } $news->update(['title' => $request->input('title'), 'content' => $request->input('content'), 'status' => $request->input('status'), 'user_id' => $user->id, 'image' => $imageName]); /* * Register Update Tags */ $selected = $this->registerTags($request); //آی دی های تگ های جدید $news->tags()->sync($selected); //sync -> insert new tag and remove old tags Flash::success(trans('messages.newsEdited')); return redirect()->back(); }