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

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

问题描述

您好,我在使用 laravel 上传图片时遇到以下错误:调用成员函数 getClientOriginalExtension() on null".

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

推荐答案

在你的 form:open 你需要 'files' =>true 如下所示

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

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

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

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

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