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

查看:2535
本文介绍了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">

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

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