【问题标题】:Call to a member function getRealPath() on string"调用字符串上的成员函数 getRealPath()"
【发布时间】:2019-02-06 09:36:28
【问题描述】:

我想在提交包含所有数据和附件(文件、图像)的表单后发送邮件。 我猜它返回字符串值。如何解决这个问题。

控制器.php

  $fileNameToStore= $filename.'_'.time().'.'.$extension;
            //upload image
            $path = $request->file('file')->storeAs('Circularfs',$fileNameToStore);
            //dd($path);
        }else{
            $fileNameToStore = 'noimage.jpg';
        }
            $cfile = new circularfs;
            $cfile->title = $request->input('title');
            $cfile->department = $request->input('department');
            $cfile->file = $fileNameToStore;
            $cfile->save();

            $to_email = "abc@gmail.com";
            \Mail::to($to_email)->send(new \App\Mail\circularfs($cfile));

App\Mail\circularfs.php错误截图在这里

【问题讨论】:

    标签: laravel-5.7 laravel-mail


    【解决方案1】:

    你能在这里显示你的表单代码吗? 您使用的是 enctype="multipart/form-data" 还是 'files'=>true?

    <form method="POST" action="http://example.com" enctype="multipart/form-data">
    </form>
    
     {!! Form::open(['url' => route('myRoute'), 'method' => 'post', 'files' => true]) !!}
    

    【讨论】:

    • {!! Form::open(['url' => route('Circularfs.store'), 'method' => 'post', 'files' => true]) !!} 使用这个
    • 做 var_dump($request->file('file'));
    • ->attach($this->cfile['file']->getRealPath(), [...] 我在这一行遇到错误,是的,我在构造函数中使用 dd($cfile) customemail.php 文件数据即将到来
    • 打印 var_dump($request->file('file')); 的响应
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-18
    • 2016-05-10
    • 2018-08-26
    • 2016-08-06
    • 1970-01-01
    相关资源
    最近更新 更多