Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(News $new, Request $request)
 {
     $new->update($request->except('image'));
     if ($request->hasFile('image')) {
         $file = $request->file('image');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension();
         $image = Carbon::now() . ' - ' . $filename . '.' . $extension;
         $destinationPath = public_path('/uploads/images/');
         $request->file('image')->move($destinationPath, $image);
         $new->image = $image;
         $new->update();
     }
     flash()->info('Berita telah diperbarui!');
     return redirect('/dashboard/news');
 }
Example #2
0
 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();
 }
Example #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \App\Http\Requests\NewsRequest $request
  * @param  \App\News $news
  * @return \Illuminate\Http\Response
  */
 public function update(Requests\NewsRequest $request, News $news)
 {
     DB::transaction(function () use($request, $news) {
         $update = ['active' => $request->get('active'), 'sort' => $request->get('sort')];
         if ($this->systemAdmin) {
             $update['department_id'] = $request->get('department_id');
         }
         $news->update($update);
         foreach ($news->langs as $lang) {
             $lang->update(['title' => $request->get('title_' . systemTrans($lang['lang_id'])), 'description' => $request->get('description_' . systemTrans($lang['lang_id']))]);
         }
     });
     return redirect(action('Admin\\NewsController@index'))->with('success', 'updated');
 }