Laravel在null上调用成员函数getClientOriginalExtension()
问题描述:
你好我在使用laravel上传图像时出现以下错误:在null上调用成员函数getClientOriginalExtension()。
Hello im getting the following error while upload an image using laravel: "Call to a member function getClientOriginalExtension() on null".
这是我的控制器:
$imageName = rand(11111, 99999) . '.' . $request->file('image')->getClientOriginalExtension();
$destinationPath = 'events';
$fileName = rand(11111, 99999) . '.' . $extension;
$upload_success = $image->move($destinationPath, $imageName);
这是我的观点:
{!! Form::file('image', null, ['class' => 'form-control']) !!}
如何将$ imageName保存到数据库中的pic字段。我试过这个,但它不起作用。该字段在表格中保持空白。
How do i save the $imageName to the pic field in my database. I tried this but it doesn't work. The field remains empty in the table.
$task=$request->user()->tasks()->create([
'name' => $request->name,
'description' => $request->description,
'location' => $request->location,
'pic' => $imageName,
]);
答
:打开你需要'files'=> true
如下所示
Form::open('your_path', array('files'=> true))
或
<form action="yout path" method="post" enctype="multipart/form-data">