/**
  * Store a newly created resource in storage.
  *
  * @param  CreatePostRequest $request
  * @return Response
  */
 public function store(CreatePostRequest $request, $category_id)
 {
     // save post
     $post = new Post();
     $post->fill($request->all());
     $post->category_id = $category_id;
     $post->save();
     // if have attachment, create the attachment record
     if ($request->hasFile('attachment')) {
         // generate filename based on UUID
         $filename = Uuid::generate();
         $extension = $request->file('attachment')->getClientOriginalExtension();
         $fullfilename = $filename . '.' . $extension;
         // store the file
         Image::make($request->file('attachment')->getRealPath())->resize(null, 640, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->save(public_path() . '/attachments/' . $fullfilename);
         // attachment record
         $attachment = new Attachment();
         $attachment->post_id = $post->id;
         $attachment->original_filename = $request->file('attachment')->getClientOriginalName();
         $attachment->filename = $fullfilename;
         $attachment->mime = $request->file('attachment')->getMimeType();
         $attachment->save();
     }
     return redirect('category/' . $category_id . '/posts');
 }
Example #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param CreatePostRequest $request
  * @return Response
  */
 public function store(CreatePostRequest $request)
 {
     $post = new Post();
     $post->fill($request->all());
     $post->user_id = Auth::id();
     if ($request->hasFile('image')) {
         $file = $request->file('image');
         $patch = 'images/posts/';
         $name = $post->title . '.' . $file->getClientOriginalExtension();
         $image = $patch . $name;
         Image::make($file)->fit(1140, 400)->save($image);
         $post->image = $image;
     }
     $post->save();
     $message = trans('messages.post_created_successfully');
     Flash::success($message);
     return redirect()->route('admin.posts.index');
 }