Laravel Call to a member function getClientOriginalExtension() on null

流过昼夜 提交于 2019-12-07 12:39:09

问题


Hello im getting the following error while upload an image using laravel: "Call to a member function getClientOriginalExtension() on null".

Here is my controller:

$imageName = rand(11111, 99999) . '.' . $request->file('image')->getClientOriginalExtension();
            $destinationPath = 'events';
            $fileName = rand(11111, 99999) . '.' . $extension;
            $upload_success = $image->move($destinationPath, $imageName);

Here is my view:

{!! Form::file('image', null, ['class' => 'form-control']) !!}

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,
        ]);

回答1:


in your form:open you need the 'files' => true like below

Form::open('your_path', array('files'=> true))

or

<form action="yout path" method="post" enctype="multipart/form-data">



回答2:


This means that no file input has been seen for that file. So, check that you input something in each file input



来源:https://stackoverflow.com/questions/37124454/laravel-call-to-a-member-function-getclientoriginalextension-on-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!