亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Eloquent 模型的 Laravel 通知

Eloquent 模型的 Laravel 通知

PHP
隔江千里 2023-03-26 14:43:15
我正在嘗試使用來自非用戶 Eloquent 模型的 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\DriverAlloted 是通知;如果我用它工作的任何用戶 (App\User) 替換驅動程序,我怎樣才能讓它為 App\Driver 工作
查看完整描述

1 回答

?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

當通知請求頻道時mail,Laravel 從特征中調用此代碼Illuminate\Notifications\RoutesNotifications(由特征擴展Illuminate\Notifications\Notifiable)


/**

     * Get the notification routing information for the given driver.

     *

     * @param  string  $driver

     * @param  \Illuminate\Notifications\Notification|null  $notification

     * @return mixed

     */

    public function routeNotificationFor($driver, $notification = null)

    {

        if (method_exists($this, $method = 'routeNotificationFor'.Str::studly($driver))) {

            return $this->{$method}($notification);

        }


        switch ($driver) {

            case 'database':

                return $this->notifications();

            case 'mail':

                return $this->email;

        }

    }

因此,您有兩種解決方法:


您的Driver模型需要有一個email屬性,該屬性將成為郵件到達的路線。


在您的模型中定義一個routeNotificationForMail方法,該方法將以自定義方式計算路線


/**

 * @param  \Illuminate\Notifications\Notification|null  $notification

 * @return string

 */

public function routeNotificationForMail($notification)

{

    return $this->address;

}


查看完整回答
反對 回復 2023-03-26
  • 1 回答
  • 0 關注
  • 120 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號