Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 压倒;电邮;应呈报特质的属性_Php_Laravel_Email - Fatal编程技术网

Php 压倒;电邮;应呈报特质的属性

Php 压倒;电邮;应呈报特质的属性,php,laravel,email,Php,Laravel,Email,我试图在一款没有email属性(实际上它有一封付款人(email)的车型中使用Laravel的法定特征 因此,我深入研究了应呈报的特征代码,发现它使用了RoutesNotifications特征中的RouteNotifications for方法,因此我决定覆盖它以实现我想要的行为 原始方法代码为: public function routeNotificationFor($driver) { if (method_exists($this, $method = 'routeNo

我试图在一款没有email属性(实际上它有一封付款人(email)的车型中使用Laravel的法定特征

因此,我深入研究了应呈报的特征代码,发现它使用了RoutesNotifications特征中的RouteNotifications for方法,因此我决定覆盖它以实现我想要的行为

原始方法代码为:

    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()为什么不做一个呢?很高兴它有帮助:-)