图像上传到存储层52不使用干预(不使用输入)

时间:2016-10-11 00:57:12

标签: php xampp laravel-5.2

我不知道自己做错了什么,这行代码无效

public function store(Request $request)
{
    // validate the data
    $this->validate($request, array(
            'title'         => 'required|max:255',
            'slug'          => 'required|alpha_dash|min:5|max:255|unique:posts,slug',
            'category_id'   => 'required|integer',
            'body'          => 'required'
        ));
    // store in the database
    $post = new Post;
    $post->title = $request->title;
    $post->slug = $request->slug;
    $post->category_id = $request->category_id;
    $post->body = $request->body;
    if ($request->hasFile('featured_image')) {
      $image = $request->file('featured_image');
      $filename = time() . '.' . $image->getClientOriginalExtension();
      $location = public_path('images/' . $filename);
      Image::make($image->getRealPath())->resize('800', '400')->save($location);
      $post->image = $filename;
    }
    $post->save();
    $post->tags()->sync($request->tags, false);
    Session::flash('success', 'The blog post was successfully save!');
    return redirect()->route('posts.show', $post->id);
} 

我的帖子正在保存,但我无法在图片文件夹或数据库中找到图像,并且不会出现任何错误。

0 个答案:

没有答案