简体   繁体   English

自定义laravel强化email验证使用mailjet模板

[英]Customize laravel fortify email verification to use a mailjet template

I've been trying to get fortify's native email verification feature to use mailjet so templates can easily be adjusted.我一直在尝试让 fortify 的原生 email 验证功能使用 mailjet,以便轻松调整模板。 I've hit a bit of a roadblock as all tutorials and sources I've found are all about blade templates.我遇到了一些障碍,因为我发现的所有教程和资源都是关于刀片模板的。 Does someone have some pointers in the right direction or perhaps personal experience setting this up?有人在正确的方向上有一些指示,或者可能有个人经验来设置它吗?

Thanks in advance!提前致谢!

You need to bind your own implementation of Laravel\Fortify\Contracts\VerifyEmailViewResponse in the FortifyServiceProvider class.您需要在 FortifyServiceProvider class 中绑定您自己的Laravel\Fortify\Contracts\VerifyEmailViewResponse FortifyServiceProvider

# app/Providers/FortifyServiceProvider.php

namespace App\Providers;

use App\Actions\Fortify\YourClassHere;
use Laravel\Fortify\Contracts\VerifyEmailViewResponse;

class FortifyServiceProvider extends ServiceProvider
{
    public function boot()
    {
        app()->singleton(VerifyEmailViewResponse::class, YourClassHere::class);
    }
}
# app/Actions/Fortify/YourClassHere.php

namespace App\Actions\Fortify;

use Laravel\Fortify\Contracts\VerifyEmailViewResponse;

class YourClassHere extends VerifyEmailResponse
{
    public function toResponse($request)
    {
        // your logic here.
        // since mailjet uses an api, perhaps return the response of a curl call,
        // or a response form Http::get(...)
        // or use a third-party package like laravel-mailjet (https://mailjet.github.io/laravel-mailjet/)
    }
}

The logic that sends the verification email is part of the Illuminate\Auth\MustVerifyEmail trait.发送验证 email 的逻辑是Illuminate\Auth\MustVerifyEmail特征的一部分。 If you want to change it, you need to override it in your User model.如果你想改变它,你需要在你的User model 中覆盖它。

class User extends Authenticatable
{
    /**
     * Send the email verification notification.
     *
     * @return void
     */
    public function sendEmailVerificationNotification()
    {
        // your logic here.
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM