发送通知时出错 'Call to undefined method App\Models\Role::routeNotificationFor()'

error when sending a notification 'Call to undefined method App\Models\Role::routeNotificationFor()'

我正在构建一个网络应用程序,在管理员(担任经理的角色)批准预订后,预订将传递给另一个管理员(担任会计师的角色),然后他开始处理 it.I 希望经理在批准后仅向会计师发送通知 booking.i 尝试了下面的代码并将其发送给所有管理员,这不是我想要实现的

    $users=User::where('is_admin','1')->get();
    Notification::send($users,new Newbookingrecieved($bookingstatus));

然后我尝试从角色模型中获取电子邮件 $users=Role::where('Role_name','The Accountant')->get(); Notification::send($users,new Newbookingrecieved($bookingstatus));

但它响应错误

BadMethodCallException 调用未定义的方法 App\Models\Role::routeNotificationFor()

这是我的通知

<?php

namespace App\Notifications;

use App\Models\Bookings;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class Newbookingrecieved extends Notification
{
    use Queueable;

    public $bookingstatus;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($bookingstatus)
    {
        $this->bookingstatus = $bookingstatus;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->greeting('Hello there sir/madam')
            ->subject('New Booking by' .$this->bookingstatus->full_name)
            ->line('We have received a new Booking and approved it to you to request payment from the client' . $this->bookingstatus->email)
            ->action('Review This Booking', route('changestatus', $this->bookingstatus->id));
                    
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

这里是所有的角色

我怎样才能做到这一点,以便将通知发送给唯一的管理员,而不会将通知发送给其他管理员。

由于我不知道你的 User 模型的结构,我假设有一个 role_id 字段。

这是我的一个旧项目中的一段代码,我将根据您的喜好对其进行修改(对我有用):

$users = User::where('role_id', 3)->get(); //3 is the id of The Accountant role
Notification::send($users, new Newbookingrecieved($bookingstatus));