Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Notification - Call to a member function routeNotificationFor() on string

Laravel 5.5

Controller

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 (Notification)

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

When calling this controller I am getting this error.

enter image description here

$staffs.

{  
   "staffId":45,
   "forname":"Eldhose",
   "surname":"John",
   "categoryId":2,
   "email":"[email protected]",
   "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"
}

Please help me on this.... Thanks

like image 912
Jishad Avatar asked Mar 24 '18 14:03

Jishad


People also ask

What is notify () in laravel?

Laravel Notify is a package that lets you add custom notifications to your project.

How do I broadcast a notification in laravel?

To inform Laravel that a given event should be broadcast, you must implement the Illuminate\Contracts\Broadcasting\ShouldBroadcast interface on the event class. This interface is already imported into all event classes generated by the framework so you may easily add it to any of your events.

How do I get email notifications in laravel?

Send Email Notifications in Laravel php use App\Notifications\Newvisit; Route::get('/', function () { $user = App\User::first(); $user->notify(new Newvisit("A new user has visited on your application.")); return view('welcome'); });


1 Answers

Notification::send() requires the first argument to be an object, usually one that uses the Notifiable trait. You pass just a string holding email address, hence the error.

If you simply want to send a notification to given email address, you'll need to use on-demand notifications. The following should do the trick:

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

For more details see the docs: https://laravel.com/docs/5.6/notifications#sending-notifications

Latest docs: https://laravel.com/docs/9.x/notifications#on-demand-notifications

like image 123
jedrzej.kurylo Avatar answered Sep 16 '22 22:09

jedrzej.kurylo