【问题标题】:Laravel Notification - Call to a member function routeNotificationFor() on stringLaravel 通知 - 在字符串上调用成员函数 routeNotificationFor()
【发布时间】:2018-09-03 02:27:30
【问题描述】:

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 !!');
}

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!');
}

调用此控制器时出现此错误。

$staffs.

{  
   "staffId":45,
   "forname":"Eldhose",
   "surname":"John",
   "categoryId":2,
   "email":"devhelloworld@gmail.com",
   "mobile":"07588593278",
   "whatsappNumber":"57656578658",
   "gender":1,
   "address":"Poole",
   "pincode":null,
   "modeOfTransport":1,
   "pickupLocation":"Office",
   "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"
}

请帮我解决这个问题......谢谢

【问题讨论】:

  • 能否查看员工和邮箱中是否有数据。
  • 是的。人员数组中的数据

标签: php email laravel-5 laravel-5.5 laravel-notification


【解决方案1】:

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

如果您只是想向给定的电子邮件地址发送通知,则需要使用按需通知。以下应该可以解决问题:

Notification::route('mail', $email)->notify(new NewBooking($email));

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

【讨论】:

  • 但我使用的是 not trait。请告诉我如何解决它。
  • 我不明白你为什么从这里调用路由。你能告诉我更多关于你的答案吗?
  • 如果您不使用特征,我的答案中的代码将起作用。请参阅有关我发布的按需通知的文档。当您没有具有 Notifiable 特征的对象而只有一个电子邮件地址时,这就是您使用的方法。
  • Route 在 v5.5 中工作,在 5.3 中没有按需通知
猜你喜欢
  • 2020-03-01
  • 2021-07-20
  • 1970-01-01
  • 2020-01-08
  • 2021-12-10
  • 1970-01-01
  • 2019-04-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多