我目前正在写一个包裹,我需要邮寄一些东西。
但是,我希望用户可以选择通过提供接口类来解决他们自己的电子邮件类,例如这里:
Mail::to($user)
->send(app(InvoiceContractMail::class));
我知道这种语法是错误的,但我想将合同类解析为用户提供的内容。
例如,Fortify 包使用了类似的东西。
Fortify::createUsersUsing(CreateNewUser::class);
// is intern nothing different than
app()->singleton(CreatesNewUsers::class, $callback);
知道我该怎么做吗?
目前,我将此界面作为我的第一次尝试:
interface InvoiceContractMail extends Mailable
{
public function __construct(Model $user, string $invoicePath);
public function build();
}