Пример #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function postEdit(BlogRequest $request, Blog $blog)
 {
     $picture = "";
     if ($request->hasFile('image')) {
         $file = $request->file('image');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension() ?: 'png';
         $folderName = '/uploads/blog/';
         $picture = str_random(10) . '.' . $extension;
         $blog->image = $picture;
     }
     $blog->update($request->except('image', '_method', 'tags'));
     if ($request->hasFile('image')) {
         $destinationPath = public_path() . $folderName;
         $request->file('image')->move($destinationPath, $picture);
     }
     $blog->retag($request['tags']);
     return redirect('admin/blog');
 }
Пример #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update(BlogRequest $request, Blog $blog)
 {
     if ($request->hasFile('image')) {
         $file = $request->file('image');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension() ?: 'png';
         $folderName = '/uploads/blog/';
         $picture = str_random(10) . '.' . $extension;
         $blog->image = $picture;
     }
     if ($request->hasFile('image')) {
         $destinationPath = public_path() . $folderName;
         $request->file('image')->move($destinationPath, $picture);
     }
     $blog->retag($request['tags']);
     if ($blog->update($request->except('image', '_method', 'tags'))) {
         return redirect('admin/blog')->with('success', trans('blog/message.success.update'));
     } else {
         return Redirect::route('admin/blog')->withInput()->with('error', trans('blog/message.error.update'));
     }
 }
 private function saveImage(Blog $blog, BlogRequest $request)
 {
     if ($request->file('image')) {
         $imageName = $blog->id . '.' . $request->file('image')->getClientOriginalExtension();
         $newExt = 'images/catalog/' . $imageName;
         $img = Image::make($request->file('image'))->orientate()->heighten(300);
         $img->save(public_path($newExt));
     }
 }