10

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":"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"
}

Please help me on this.... Thanks

2
  • Can u check whether the data is there in staffs and email.
    – Jigs1212
    Mar 24, 2018 at 15:05
  • Yes. Data in staffs array
    – Jishad
    Mar 24, 2018 at 15:11

1 Answer 1

34

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

4
  • But I am using not trait. Please tell me how to solve it.
    – Jishad
    Mar 24, 2018 at 15:49
  • I didn't understand why you are calling route from here. can u please tell me more about your answer.
    – Jishad
    Mar 24, 2018 at 16:33
  • If you're not using a trait, the code in my answer will work. See docs on the on-demand notifications that I posted. That's what you use when you don't have an object with Notifiable trait but just an email address. Mar 24, 2018 at 17:00
  • Route is working in v5.5 in 5.3 there is no notification on demand
    – Wraith
    May 3, 2019 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.