Ad

Call To A Member Function Notify() On Integer In LARAVEL 5.8

- 1 answer

I am working on a task schedule. The flow is I need to send notification as a reminder for their duedate.

here's my console\command\remindDuedate

class remindDuedate extends Command
{
    protected $signature = 'remindDuedate:run';   
    protected $description = 'Command description';    
    public function __construct()
    {
        parent::__construct();
    }    
    public function handle()
    {
        while (true) {
            $loanapplications = LoanApplication::where('archive',false)->where('status','=',2)->get();          

            foreach ($loanapplications as $application) {

                $user = $application->user_id;

                $date_approval = Carbon::createFromTimestamp(strtotime($application->date_approval));

                $duration = $application->loanDuration->num_days;
                $duedate_warning = $duration-3;

                $reminder_date = $date_approval->addDays($duedate_warning)->toDateString();

                $now = Carbon::now('Asia/Manila')->toDateString();
                $duedate = Carbon::now('Asia/Manila')->addDays(3)->toDateString();

                if($reminder_date == $now) {

                    $user->notify(new remindDuedateNotif());
                }
            }           
        }
    }
}

php artisan remindDuedate:run

enter image description here

remindDuedateNotif

enter image description here

Why do I getting the "Call to a member function notify() on integer"

Thank you in advance!

Ad

Answer

You are not fetching the user, therefor the user is still an integer, set it like so.

$user = User::find($application->user_id);

EDIT

As you can see your notification takes a user as the first argument. Therefor send it with it.

$user->notify(new remindDuedateNotif($user));

This is weird to send and notify on the User object and pass it. You are in luck as every $notifiable parameter is actually an user, as it would be the object you send it from.

So remove $user from __contruct() and everywhere you access the user, you can do the following.

'user_id' => $notifiable->id,
Ad
source: stackoverflow.com
Ad