编程语言
首页 > 编程语言> > php – 上传未保存的文件时“尝试获取非对象属性”

php – 上传未保存的文件时“尝试获取非对象属性”

作者:互联网

我有一个模型,其文件关系使用OctoberCMS的system_files.

public $attachOne = [
    'return_file' => ['System\Models\File', 'public' => false, 'delete' => true]
    ];

在fields.yaml我有表格

   return_file:
        label: Attach File
        type: fileupload
        mode: file
        span: right

现在,在我保存之前或之后,我想将图像从其目录移动到我的插件中的自定义目录. afterSave()似乎没有检索文件路径来移动它.

但是在system_files中我看到MySQL workbench实际上已经上传了它

然而,当我在后端点击保存时,我得到“试图获得非物体的属性”

这是afterSave()函数中的内容.

public function afterSave()

{

$custom_path = plugins_path() . '/acme/request/uploads/';
$file = $this->return_file->getPath();
$move_file = $file->move($custom_path);

}

甚至可以在后端上传并在保存之前/之后移动文件?

解决方法:

问题是文件在afterSave()中还没有完全存在,它仍然作为延迟绑定存在.试试这个:

$this->return_file()->withDeferred($this->sessionKey)->first()->getPath();

标签:php,laravel,octobercms
来源: https://codeday.me/bug/20190823/1700209.html