php - 在 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>
有人可以帮助我吗,拜托!
谢谢,
解决方案
您不会在实体之间传递或接收任何参数: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
推荐阅读
- java - 将空 JSONArray 转换为字符串
- sql - postgres: Any way to insert multiple tables into another table in the same query?
- php - 在 WooCommerce 中添加和处理自定义结帐选择字段的问题
- command-line-interface - 安装 Lucene.net CLI
- typescript - 根据数组文字区分联合
- css - 即使提供了模板路径,tailwindcss 也不会被清除
- php - 如何优化以下雄辩的查询?
- python - 为什么 matplotlib 会为数据列表生成线性图?
- javascript - 动态页面创建 - React
- javascript - 在 node.js 中使用函数数组可以正常工作,但是 await 不等待?