Php 压倒;电邮;应呈报特质的属性
我试图在一款没有email属性(实际上它有一封付款人(email)的车型中使用Laravel的法定特征 因此,我深入研究了应呈报的特征代码,发现它使用了RoutesNotifications特征中的RouteNotifications for方法,因此我决定覆盖它以实现我想要的行为 原始方法代码为:Php 压倒;电邮;应呈报特质的属性,php,laravel,email,Php,Laravel,Email,我试图在一款没有email属性(实际上它有一封付款人(email)的车型中使用Laravel的法定特征 因此,我深入研究了应呈报的特征代码,发现它使用了RoutesNotifications特征中的RouteNotifications for方法,因此我决定覆盖它以实现我想要的行为 原始方法代码为: public function routeNotificationFor($driver) { if (method_exists($this, $method = 'routeNo
public function routeNotificationFor($driver)
{
if (method_exists($this, $method = 'routeNotificationFor'.Str::studly($driver))) {
return $this->{$method}();
}
switch ($driver) {
case 'database':
return $this->notifications();
case 'mail':
return $this->email;
case 'nexmo':
return $this->phone_number;
}
}
我在我的支付模式中用以下方式覆盖了它:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Illuminate\Notifications\Notifiable;
use App\Notifications\PaymentNotify;
class Payment extends Model
{
use Notifiable;
public function routeNotificationFor($driver)
{
if (method_exists($this, $method = 'routeNotificationFor'.Str::studly($driver))) {
return $this->{$method}();
}
switch ($driver) {
case 'database':
return $this->notifications();
case 'mail':
return $this->payer_email;
case 'nexmo':
return $this->phone_number;
}
}
}
我刚刚创建了一个名为routeNotificationForMail的方法,就像@Jonathon建议的那样,我做得很好
public function routeNotificationForMail(){
return $this->payer_email;
}
感谢他让我睁开眼睛,我被一杯水淹死了……出于兴趣,试着放一个dd($driver)
就在if(method_exists(…){
就在语句内部,返回$this->{$method}()
。这有什么用吗?另外,我建议在您的模型中创建一个routeNotificationForMail
方法,并返回您想通过该方法发送电子邮件的地址。哦,在您发布的代码中,您没有更改return$this->email;
位;-)哦,对了!只是复制了错误的方法(原版,不是我的模型)。我将尝试创建routeNotificationForMail()为什么不做一个呢?很高兴它有帮助:-)