Framework: Error Call to a member function delay() on null when call in $user->notify($natifictionclass)->delay()

Created on 3 Feb 2017  路  2Comments  路  Source: laravel/framework

  • Laravel Version: 5.3
  • PHP Version:
  • Database Driver & Version:

Description:

Call to a member function delay() on null

I am getting above when i am calling notify method with dealy.

Notication class i am geting.in job table data is store but i am getting error in call to member function delay on null. can one hel

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class User extends Model
{
    //
    use Notifiable;
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'user';
    /**
     .....
}

notification class

    namespace App\Notifications;

    use App\Channels\PushChannel;
    use App\Channels\SmsChannel;
    use App\Libraries\Helper;
    use App\Waitlists;

    use Illuminate\Bus\Queueable;
    use Illuminate\Notifications\Notification;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

    use Illuminate\Queue\SerializesModels;
    use Illuminate\Queue\InteractsWithQueue;

    class WaitingPrecall extends Notification implements  ShouldBroadcast
    {

    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public $message;
    public $phone;


    public $deviceGuests;

    public function _construct()
    {

    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return $this->sendtype==1?[PushChannel::class]: [PushChannel::class,SmsChannel::class];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */

    public function toSms($notifiable)
    {
         $data=Helper::send_message($this->smstext,$this->phone);

         return $data;
    }
}

function call for

$waitPreCall=new WaitingPrecall();

....
....

$guest=User::find($waitDataNew->user->gust_id);

 $guest->notify($waitPreCall)->delay($when);//here i am getting error

Steps To Reproduce:

Most helpful comment

You call delay on the notification instance:

From the docs:

$user->notify(            (new InvoicePaid($invoice))->delay($when)         );

All 2 comments

You call delay on the notification instance:

From the docs:

$user->notify(            (new InvoicePaid($invoice))->delay($when)         );

Thanks @themsaid for your guideline and for your valuable time.

I have apply your solution after that i am not getting any error but I don't know why jobs are note save jobs table .When i am call $guest->notify($waitPreCall)->delay($when); on that time jobs has been save in database.

One more things can we apply queue to

Notification::send($users, new InvoicePaid($invoice));

function.Can you help me in this.

Was this page helpful?
0 / 5 - 0 ratings