在null上调用成员函数store()-Laravel 5.4 [英] Call to a member function store() on null - laravel 5.4

查看:249
本文介绍了在null上调用成员函数store()-Laravel 5.4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图上传图像,尽管每次提交时都会返回null错误的store().我已将表单设置为enctype ="multipart/form-data",但没有帮助.

I'm trying to upload an image though everytime I submit it's returning that the store() on null error. I've set the form to enctype="multipart/form-data" which hasn't helped.

有人能指出我正确的方向吗?

Can anyone point me in the right direction?

谢谢.

控制器内部的功能

public function store(Request $request){

  $file = $request->file('imgUpload1')->store('images');
  return back();

}

下面的表格:

<form action="/imgupload" method="POST" enctype="multipart/form-data">
  {{ csrf_field() }}
  <div class="form-group">
     <label for="imgUpload1">File input</label>
     <input type="file" id="imgUpload1">
  </div>
    <button type="submit" class="btn btn-primary">Submit</button>
</form>

已解决:在输入字段上缺少名称标签

solved: was missing name tag on input field

推荐答案

我遇到的相同问题是我在打开的表单标签中添加了 enctype ="multipart/form-data" 那应该解决它.如果没有它,laravel将无法理解该文件.

I had the same issue what I did to fix is in the opening form tag add enctype="multipart/form-data" that should fix it. With out it laravel would not understand the file.

喜欢:

<form method="POST" enctype="multipart/form-data" name="formName">

希望这可以解决您的问题.

Hope this solves your problem.

这篇关于在null上调用成员函数store()-Laravel 5.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆