为什么 Laravel 5 邮件,我附加了一个 .tmp 文件?

Why Laravel 5 mail, I attached a .tmp file?

我正在尝试在从表单发送的电子邮件中附加一个文件,问题是该文件正在发送给我 .tmp

我的控制器

public function choiceAnalyst(Request $request){

    $userSelect = $request->input('user');
    $data = User::where('id', '=', $userSelect)->first();
    $data->attach = $request->file('document')->getRealPath();

    Mail::to('eaquino@spi.com.ve')->send(new AnalystMonth($data));

    return redirect()->route('home', ['message' => 'Correo enviado correctamente']);
}

我的Class

class AnalystMonth extends Mailable
{
    use Queueable, SerializesModels;

    public $user;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(User $user)
    {
        $this->user = $user;

    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('mails.analystMonth')->attach($this->user->attach);
    }
}

我想我在获取文件时通过 getRealPath() 方法得到了 .tmp,但我不确定。如何让我的文件达到 .tmp 扩展名?

您正在收到一个 .tmp 文件,因为该文件在您将其附加到您的邮件之前从未上传到服务器。

$data->attach = storage_path('app/public/' . $request->file('document')->store('folder', 'public'));

您可以使用 Storage 外观获得相同的结果:

$data->attach = Storage::disk('public')->path($request->file('document')->store('folder', 'public'));