首页 > 解决方案 > 在 laravel 中转发数据以获取电子邮件内容

问题描述

当我触发发送按钮时,我试图将我在 Laravel 上的数据转发到 Infrastructure.blade.php。

在 Infrastructure.blade.php 我有这些代码。

@component('mail::message')
# Critical Infrastructure:  Name (want to use {{$infrastructure->name}})

You're receiving this email because our records indicate that the above Infrastructure 
is in critical condition and need to be checked asap.

Click on the button below for more details.

@component('mail::button', ['url' => 'http://localhost:8000/infrastructures/$infrastructure->id'])
View More!
@endcomponent

Thanks,<br>
{{ config('app.name') }}
@endcomponent

网页.php

Route::resource('infrastructures', 'infrastructureController');

Route::get('/email', function () {

    Mail::to('example@gmail.com')->send(new ReportInfrastructure());

    Flash::success('Email Sent Successfully. ');

    return redirect(route('infrastructures.index'));
});

报告基础设施.php

public function build()
{
    return $this->markdown('emails.infrastructure');
}

show.blade.php 我必须遵循代码,

<div class="row" style="padding-left: 20px">
@include('infrastructures.show_fields')
<a href="{{ route('infrastructures.edit', [$infrastructure->id]) }}" class="btn btn-default">Edit</a>
<a href="{{ route('infrastructures.index') }}" class="btn btn-default">Back</a>
<a href="{{ url('/email') }}" class="btn btn-primary">Send</a>
</div>

我最近尝试了这个,但没有找到页面。

<a href="{{ url('/email',[$infrastructure->id]) }}" class="btn btn-primary">Send</a>

有人可以帮助我吗,拜托!

谢谢,

标签: phplaravel

解决方案


您不会在实体之间传递或接收任何参数:URL 生成、路由、控制器、可邮寄。你需要告诉你的函数你需要通过$infrastructure

<a href="{{ url('/email',['infrastructure_id' => $infrastructure->id]) }}" class="btn btn-primary">Send</a>
Route::get('/email/{infrastructure_id}', function ($infrastructure_id) {
    $infrastructure = Infrastructure::find($infrastructure_id);
    Mail::to('tekitaamtk@gmail.com')->send(new ReportInfrastructure($infrastructure));
    Flash::success('Email Sent Successfully. ');
    return redirect(route('infrastructures.index'));
});

您需要在Class构造$infrastructure函数中接受参数才能在电子邮件中显示它 -有关更多详细信息,请参见此处的文档ReportInfrastructure


推荐阅读