Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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 用于雄辩模型的Laravel通知_Php_Laravel - Fatal编程技术网

Php 用于雄辩模型的Laravel通知

Php 用于雄辩模型的Laravel通知,php,laravel,Php,Laravel,我正在尝试使用Notifiable trait(notify())方法从非用户雄辩模型发送通知(电子邮件) 驱动模型 namespace App; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class Driver extends Authenticatable { use Notifiable; } 以及发送我正在使用的通知 $d

我正在尝试使用Notifiable trait(notify())方法从非用户雄辩模型发送通知(电子邮件)

驱动模型

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class Driver extends Authenticatable
{
  use Notifiable;
}
以及发送我正在使用的通知

  $driver->notify(new \App\Notifications\Driver\DriverAlloted($booking));
其中,$driver是一个雄辩的模型实例(app\driver.php),而\app\Notifications\driver\driverlocted是通知


如果我用任何用户(App\user)替换驱动程序,那么我如何让它为App\driver工作呢?当通知请求
mail
频道时,Laravel从
illights\Notifications\RoutesNotifications
trait(扩展为
illights\Notifications\Notifiable
trait)调用此代码

/**
*获取给定驱动程序的通知路由信息。
*
*@param字符串$driver
*@param\light\Notifications\Notification | null$Notification
*@返回混合
*/
用于($driver,$notification=null)的公共函数RoutenNotification
{
如果(方法_存在($this,$method='routeNotificationFor'.Str::studly($driver))){
返回$this->{$method}($notification);
}
交换机($driver){
案例“数据库”:
返回$this->notifications();
“邮件”案例:
返回$this->email;
}
}
因此,您有两种解决方法:

  • 您的
    驱动程序
    型号需要具有
    电子邮件
    属性,这将是邮件到达的路线

  • 在模型中定义一个
    routeNotificationForMail
    方法,该方法将以自定义方式计算路线

/**
*@param\light\Notifications\Notification | null$Notification
*@返回字符串
*/
公共功能路线通知表($通知)
{
返回$this->address;
}

当通知请求
邮件频道时,Laravel从
照亮\通知\路由通知
特征调用此代码(扩展为
照亮\通知\可通知
特征)

/**
*获取给定驱动程序的通知路由信息。
*
*@param字符串$driver
*@param\light\Notifications\Notification | null$Notification
*@返回混合
*/
用于($driver,$notification=null)的公共函数RoutenNotification
{
如果(方法_存在($this,$method='routeNotificationFor'.Str::studly($driver))){
返回$this->{$method}($notification);
}
交换机($driver){
案例“数据库”:
返回$this->notifications();
“邮件”案例:
返回$this->email;
}
}
因此,您有两种解决方法:

  • 您的
    驱动程序
    型号需要具有
    电子邮件
    属性,这将是邮件到达的路线

  • 在模型中定义一个
    routeNotificationForMail
    方法,该方法将以自定义方式计算路线

/**
*@param\light\Notifications\Notification | null$Notification
*@返回字符串
*/
公共功能路线通知表($通知)
{
返回$this->address;
}

似乎您复制了用户类,为什么要扩展Authenticatable?您的laravel版本是什么?是否有错误?您试图使用什么渠道发送通知?似乎您复制了用户类,为什么要扩展Authenticatable驱动程序?您的laravel版本是什么?是否收到错误?您试图通过哪些渠道发送通知?