#Any tricks on how to track down this Illuminate error?

83 messages · Page 1 of 1 (latest)

plain scroll
#

Hey, it's me again.

I was working on sending notifications and suddenly I started getting the error in the image attached to the post. I have absolutely no idea on what is causing this. This is happening when I send a Laravel notification.

Check my toArray() function in the notification class:

public function toArray($notifiable)
{
  return [
    'title' => $this->title,
    'content' => $this->content
  ];
}

There is nothing wrong with this. Everything is fine. The constructor set this private variables using property promotion and I am passing it when instantiating the notification class.

The only thing I think might be causing the issue is I have a replacement for the database channel which is a channel named DatabaseChannel and extends Illuminate's default one:

class DatabaseChannel extends IlluminateDatabaseChannel
{
    public function buildPayload($notifiable, Notification $notification)
    {
        return [
            'id' => $notification->id,
            'type' => get_class($notification),
            'data' => $this->getData($notifiable, $notification),
            'read_at' => null,
            'sender_id' => $notification->getSenderID()
        ];
    }
}

So far I have debugged and all variables, everything sent there is completely fine. I just don't get it why this error keeps showing up and I can't even find what is causing it or where it is happening.

Any thoughts? If you need any more information, I'll be glad to send it.

floral torrent
#

Post the full stack trace

plain scroll
#

I've been stuck on this for hours.

#

Searched everywhere, but the only similar thing I found was some people with not related issues.

floral torrent
#

Show us web.php:30

plain scroll
#

it is this second line

#

and yes, user is returning an eloquent instance alright

#

AdminNotification constructor

#

AdminNotification toArray function

floral torrent
#

Actually post the whole notification class

plain scroll
# floral torrent Actually post the whole notification class
namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class AdminNotification extends Notification
{
    use Queueable;

    public function __construct(
        private string $title,
        private string $content,
        private int $senderID,
    ) {
        //
    }

    public function getSenderID()
    {
        return $this->senderID;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        if($notifiable->isNotificationEnabled('email_system_notification')) {
            return ['mail', 'database'];
        }
        return ['database'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('teste')
            ->line('The introduction to the notification.')
            ->action('Notification Action', url('/'))
            ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'title' => $this->title,
            'content' => $this->content
        ];
    }
}
#

Here it is

#

btw @floral torrent thanks for being able to try to help

#

it means a lot for me

floral torrent
#

Yeah sorry I'm not very familiar with this part of the framework so it's taking me a while

#

Your User class uses the Notifiable trait, right?

#

Also what exact version of laravel are you on? Mine doesn't seem to match quite right with yours going by the stack trace

plain scroll
#

and I am on laravel 9

#

my stack trace always shows useless things

#

I don't get it

floral torrent
#

They're not useless

#

I'm on 9.45.1, I think you might be on an older version because the line numbers from your stack trace don't quite match mine in some classes

#

So I need to know your exact laravel version so I know where to look

plain scroll
#

I am on Laravel 9.39.0

#

Do you think updating Laravel could give us some more useful information?

floral torrent
#

Wouldn't hurt

plain scroll
#

@floral torrent I was trying to track down to the error inside the facades

#

just to see where this thing was happening

#

I got here

#

but see

floral torrent
#

I don't understand where that read_at comes from

plain scroll
#

$values = this

#

this one set to null?

floral torrent
#

yeah

plain scroll
#

it comes from databasechannel

#

do you think

#

if I remove it

#

and set it to default null in database

#

would help?

floral torrent
#

hurp so it does

plain scroll
#

but laravel's default databasechannel has it too

floral torrent
#

There's definitely something fishy going on there

plain scroll
#

I guess that's it

#

look

#

I changed read_at to Carbon's now(), just for testing

#

and the same error show up, except this time is not "null", but "Carbon" given

#

literally the same error

#

I don't get it. It was working yesterday.

floral torrent
#

wait

#

oooh

#

there it is

#

data => array(2)

plain scroll
#

this is messing up?

#

gosh you're right

#

I encoded to json

#

and it seems to work

floral torrent
#

Yes. Look at line 1011 in Grammar

plain scroll
floral torrent
#

Man I should've caught that way sooner, sorry

plain scroll
#

no, don't be sorry

#

you helped me a lot

#

I think 99% of the people wouldn't have the patience you have.

#

Thanks, I mean it. I'm really thankful.

#

the weird part is Laravel's default DatabaseChannel doesn't have json_encode

#

it is basically the same

#

but, in other hand, inside Notification model I have a private function called getData. Perhaps this caused the error?

floral torrent
#

There was no getData in the notification you showed me

plain scroll
#

But it is in the model that access the notification table

#

it is not being called

#

can't be related to this, nvm

#

it is not even called there

#

but I'm really help the problem was solved

#

thanks @floral torrent, I wish I could reward you in any way, but I am unable to

floral torrent
#

No need. Do tag the thread as Solved please

plain scroll
floral torrent
#

There's a tag called "Solved"