如何使用laravel 5.7在邮寄降价的表格单元格中显示图像?

时间:2018-12-29 05:46:33

标签: php laravel markdown github-flavored-markdown

我正在使用laravel 5.7并在刀片中开发新闻稿邮件模板,在其中显示博客文章。请查看代码:

用于在浏览器中呈现邮件模板的控制器:

$posts = [
        [
        'title' => 'Post with tags',
        'slug' => 'post-with-tags',
        'excerpt' => "Post's Short description here",
        'featured_image' => "1545299956.png",
        'campaign_source' => "campaign source",
        'campaign_name' => "campaign name",
        'campaign_medium' => "campaign medium",
        'campaign_term' => "campaign term",
        'campaign_content' => "capaign content",
            ],

        [
        'title' => 'Post with tags',
        'slug' => 'post-with-tags',
        'excerpt' => "Post's Short description",
        'featured_image' => "1545299956.png",
        'campaign_source' => "campaign source",
        'campaign_name' => "campaign name",
        'campaign_medium' => "campaign medium",
        'campaign_term' => "campaign term",
        'campaign_content' => "capaign content",
    ]
    ];


    echo (new App\Mail\EmailNewsletterForBlogPosts("Mailer Short Description", $posts))->render();

EmailNewsletterForBlogPosts

$email= $this->subject(config('app.name')." : Our newsletter")->markdown('emails.blog_post_newsletter')->with([
            'shortDescription' => $this->shortDescription,
            'posts' => $this->posts
        ]);

blog_post_newsletter.blade.php:

这正在工作

@component('mail::message')

#{{$shortDescription}}

@component('mail::table')
| Image       | Title         |
| ------------- |:-------------:|
@foreach($posts as $post)
| ![Test](http://localhost:8000/storage/blog_featured_images/1545299956.png "THIS IS WORKING")      | Right-Aligned |
@endforeach
@endcomponent



Thanks,<br>
Exchange Support
@endcomponent

但这不起作用

@component('mail::message')

#{{$shortDescription}}

@component('mail::table')
| Image       | Title         |
| ------------- |:-------------:|
@foreach($posts as $post)
@php
$imagePath = asset('storage/blog_featured_images/');
$imagePath.=$post->featured_image;
@endphp
| ![Test]({{$imagePath}} "THIS IS NOT WORKING")      | Right-Aligned |
@endforeach
@endcomponent



Thanks,<br>
Exchange Support
@endcomponent

我想这里的问题是每当我执行任何php操作(如将图像名称与路径连接)时,它就会在浏览器中显示null。 事件我尝试在$posts数组中传递完整的图像路径,但仍未显示特色图像,但浏览器返回了null

在这种情况下,请帮助我指导。

1 个答案:

答案 0 :(得分:2)

尝试以下:

$imagePath = $message->embed(asset('storage/blog_featured_images/'.$post->featured_image));