Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to a member function delay() on null on laravel notification

Hi i got this error message "Call to a member function delay() on null"

this is my code in contoller

$input  = $request->end_date;
$format = 'd/m/Y';
$date = Carbon::createFromFormat($format, $input)->toDateString();
$when = Carbon::parse($date)->subDays(7);
$this->dispatch(
   $request->user()->notify(new EndDate($asset))->delay($when)
);

I have no idea how to fix that, I'm new in programming, so I hope someone could help me to fix this error.

like image 796
jFranky Avatar asked Sep 05 '25 13:09

jFranky


1 Answers

You were close!

The delay method should be called on the EndDate notification and not chained on after the notify() method.

Also, you shouldn't need to use $this->dispatch() as the notify() method will do this for you.

$request->user()->notify((new EndDate($asset))->delay($when));

Below is the exact same code, however, I've just broken it on to multiple lines to make it clearer and easier to see:

$request->user()->notify(
    (new EndDate($asset))->delay($when)
);
like image 127
Rwd Avatar answered Sep 08 '25 01:09

Rwd