2017-10-25 00:37



I am having trouble uploading my image into database, everytime I try to upload it, the data send into the database is empty but my local disk is able to store the image and I don't know what to do. I think I might have done something wrong in the controller part


public function store1(Request $request){

   $this->validate($request, [
        'file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',

   if ($request->hasFile('file')) {
        $image = $request->file('file');
        $name = $image->getClientOriginalName();
        $size = $image->getClientSize();
        $destinationPath = public_path('/images');
        $image->move($destinationPath, $name);

        $userImage = new UserImage;
        $userImage->name = $name;
        $userImage->size = $size;

table that I wanted to upload to:

Schema::create('user_images', function (Blueprint $table) {

enter image description here

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanpie2414 duanpie2414 4年前

    In your posted code, you forgot setting the data for user_id. As I can see in your schema, it is not nullable so it should have a data.

    Also, can you try putting () in your save like so :

    点赞 评论 复制链接分享