Laravel通知 - 在字符串上调用成员函数routeNotificationFor()

Jis*_*had 4 php email laravel-5 laravel-notification laravel-5.5

Laravel 5.5

调节器

public function sendBookingSms(){
  $checkState = session()->get('checkState');
  $staffs = Staff::whereIn('staffId',$checkState)->get();
  foreach ($staffs as $staff) {
    $email = str_replace(" ","","44".substr($staff->mobile, 1)).'@mail.mightytext.net';
    Notification::send($email, new NewBooking($email));
  }
  return $staffs;
  session()->forget('checkState');
  return redirect(route('booking.current'))->with('message','Succesfully Send SMS to selected staffs !!');
}
Run Code Online (Sandbox Code Playgroud)

NewBooking.php(通知)

public function toMail($notifiable)
{
    return (new MailMessage)
                ->line('The introduction to the notification.')
                ->action('Notification Action', url('/'))
                ->line('Thank you for using our application!');
}
Run Code Online (Sandbox Code Playgroud)

调用此控制器时,我收到此错误.

在此输入图像描述

$员工.

{ "STAFFID是" 45 "的forName": "Eldhose", "姓": "约翰", "的categoryId":2, "电子邮件": "devhelloworld@gmail.com", "手机": "07588593278"," whatsappNumber ":" 57656578658" , "性别":1, "地址": "普尔", "PIN码":空, "modeOfTransport":1, "pickupLocation": "办公室", "branchId":0, "了zoneid" :1, "bandId":1, "paymentMode":1, "payRateWeekday":10 "payRateWeekNight":20, "payRateWeekendDay":10 "payRateWeekendNight":20, "payRateSpecialBhday":11 "payRateSpecialBhnight":15 ,"payRateBhday":11,"payRateBhnight":15,"status":1,"deleted_at":null,"created_at":"2018-02-26 22:16:44","updated_at":"2018-02 -26 22:16:44"}

请帮助我....谢谢

jed*_*ylo 12

Notification :: send()要求第一个参数是一个对象,通常是一个使用Notifiable trait的对象.您只传递一个包含电子邮件地址的字符串,因此出错.

如果您只是想向给定的电子邮件地址发送通知,则需要使用按需通知.以下应该做的伎俩:

Notification::route('mail', $email)->notify(new NewBooking($email));
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅文档:https://laravel.com/docs/5.6/notifications#sending-notifications