/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(ArticleRequest $request) { $article = Auth::user()->articles()->create($request->all()); $this->syncTags($article, $request->input('tag_list')); if ($request->hasFile('cover')) { $this->uploadFile($article, $request->file('cover')); } if ($request->has('twitter')) { $this->tweet($article); } session()->flash('flash_message', 'Se ha publicado tu artículo'); return redirect('admin/articles'); }
/** * Cập nhật bài viết * * @param Article $article * @return Response */ public function update(Article $article, ArticleRequest $request, ImageInterface $image) { $data = $request->all(); if ($request->hasFile('image')) { // Trước hết cần xóa các file ảnh cũ nếu có if ($article->image) { \File::delete(public_path(config("image.paths") . 'articles/large' . $article->image)); \File::delete(public_path(config("image.paths") . 'articles/medium' . $article->image)); \File::delete(public_path(config("image.paths") . 'articles/small' . $article->image)); } $image->init($request, 'articles')->save('large')->save('medium')->save('small'); $data = array_replace($data, ['image' => $image->name]); } $article->update($data); $article->syncTags($request->input('tag_list', [])); return redirect('admin/article')->with('flash_message', config('blog.message.updated')); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(ArticleRequest $request, $id) { $article = Article::find($id); //Check fileImage if ($request->hasFile('image')) { $image = $request->file('image'); $imagename = time() . '-' . $image->getClientOriginalName(); $image->move(public_path() . '/image', $imagename); } else { $imagename = $article->image; } //Status if ($request->Input('status') == false) { $status = 0; } else { $status = 1; } //data $data = ['name' => $request->get('name'), 'summary' => $request->get('summary'), 'content' => $request->get('content'), 'image' => $imagename, 'status' => $status]; //update //dd($data); $article->update($data); return redirect()->route('article.index'); }
/** * update an existing article * * @param integer $id * @param ArticleRequest $request * @return Response */ public function update(Article $article, ArticleRequest $request) { $article->update($request->except('image')); $article->slug = str_slug($request->title, '-'); if ($request->hasFile('image')) { $file = $request->file('image'); $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $image = sha1($filename . time()) . '.' . $extension; $destinationPath = public_path('/uploads/images/'); $request->file('image')->move($destinationPath, $image); $article->image = $image; } $article->update(); $this->syncTags($article, $request->input('tag_list')); flash()->info('Artikel telah diperbarui!'); return redirect('/dashboard/articles'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(ArticleRequest $request, $id) { $article = Article::find($id); if ($request->hasFile('image')) { $path = base_path() . '/public/images'; $file = $request->input('image'); // $file->fit(120,90); $fileName = $request->file('image')->getClientOriginalName(); $request->file('image')->move($path, $fileName); $article->image = $fileName; } $article->update($request->all()); for ($i = 0; $i < sizeof($request->input('dealname')); $i++) { $deal = $article->deals()->where('dayID', $i + 1)->first(); $deal->dealname = $request->input('dealname')[$i]; $deal->save(); } // TO UPDATE CATEGORIES $categoriesId = $request->input('categoryList'); $article->categories()->sync($categoriesId); $daysId = $request->input('dayList'); $article->days()->sync($daysId); return redirect('/'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, ArticleRequest $request) { $article = Article::findOrFail($id); $article->update($request->all()); // update image if ($request->hasFile('image')) { $image_filename = $request->file('image')->getClientOriginalName(); $image_name = date("Ymd-His-") . $image_filename; $public_path = 'images/articles/'; $destination = base_path() . $public_path; $request->file('image')->move($destination, $image_name); $article->image = $public_path . $image_name; $article->save(); } $tagsId = $request->input('tag_list'); if (!empty($tagsId)) { /* select */ $article->tags()->sync($tagsId); } else { /* Not select */ $article->tags()->detach(); } session()->flash('flash_message', 'Edit completed'); return redirect('articles'); }
public function update($id, ArticleRequest $request) { $request_data = $request->all(); $article = Auth::user()->articles()->findOrFail($id); if ($request->hasFile('image_file')) { $image_file = $request_data['image_file']; unset($request_data['image_file']); $path = storage_path("app/articles/" . $article->id . "/"); $request_data['image_name'] = $this->generateImageName($image_file->getClientOriginalExtension()); $request_data['mime_type'] = $image_file->getClientMimeType(); $this->saveImage($path, $image_file, $request_data['image_name']); } //$article = Article::findOrFail($id); $article->update($request_data); return redirect('articles'); }