【发布时间】:2019-12-14 00:09:41
【问题描述】:
我正在尝试将徽标作为图像嵌入电子邮件中。
当我使用<img src="{{ $message->embed($pathToImage) }}"> 函数时出现错误
无法打开文件进行读取 [https://roadshow.test/storage/img/Email/Image_1_3a24d02162cb4c38a9c97009d527d53c.png]
电子邮件生成器如下所示:
return $this->subject("Event - {$subjectDate}")
->view('emails.index')
->with(['pathToImage' => url('/storage/img/Email/Image_1_3a24d02162cb4c38a9c97009d527d53c.png')]);
如果我在我的视图中使用url('....') 函数,图片正在加载,我可以毫无问题地看到它。
我还尝试使用 Laravel public_path('/img/Email/Image_1_3a24d02162cb4c38a9c97009d527d53c.png') 助手获取图像。但这不起作用,虽然我使用 php artisan 命令将存储与公用文件夹链接起来。
我的文件系统配置:
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
而且我不使用电子邮件降价。环境设置在宅基地上。我所有的文件都在上传的"/home/vagrant/code/roadshow/storage/img/Email/Image_1_3a24d02162cb4c38a9c97009d527d53c.png" 文件夹中。
我在 Windows 10 上运行宅基地,这是 Windows 中的路径
【问题讨论】:
-
您是否使用
symlink命令在您的storage和public文件夹之间创建符号链接? -
是的,我在我的问题中提到了它。我用这个命令
php artisan storage:link -
我读过那部分,我的错!
-
您必须将存储路径传递给它,而不是 url 或公共路径。您可以为此使用 storage_path 帮助程序。 laravel.com/docs/5.8/helpers#method-storage-path如果您需要更多帮助,请提供该文件在项目中的位置。
-
我已经更新了我的问题。