构建一个Laravel应用,其中将免费列出许多企业。所以我的问题是,如果最终用户希望与特定企业联系,则该站点的管理员(即ME)应该会收到通知,
“ ABC用户”已要求为“ XYZ Industries”安排通话
答案 0 :(得分:1)
请提供更多代码以获得更详细的答案。
假设您的公司在App\Business
模式下列出
最简单的方法是,首先创建一个电子邮件类:
在终端:php artisan make:mail NotifyMeOfBusinessCreated
然后在emails\notify_me_of_business_created.blade.php
在NotifyMeOfBusinessCreated.php
中的下一个将use $business;
添加到类的正文中。
您的构造方法应类似于
public function __construct($business)
{
$this->business = $business;
}
您的构建方法应为
public function build()
{
return $this->from('me@mydomain.com')
->view('emails.notify_me_of_business_created')
->subject('New business added');
}
您的emails/notify_me_of_business_created.blade.php
应该类似于
{{ $business->name }} created.
最后在您的AppServiceProvider.php
中添加:
use App\Business;
....
public function boot() {
Business::created(function ($business) {
Mail:to('me@mydomain.com')->send(new NotifyMeOfBusinessCreated($business))
});
...
}