FilamentF
Filamentβ€’3y ago
Quin.

Notification error , Undefined array key

Hello! I am making a notification but my domain_check_id is undefined array key, Anyone has a idea how to fix this i don't understand what is miss with it.

public function __construct(public User $user, public DomainCheck $domainCheck, public string $message, public string $categories)
    {
    }

    public function via($notifiable): array
    {
        return ['database'];
    }

    public static function toFilamentNotification(): FilamentNotification
    {
        return FilamentNotification::make()
            ->constructUsing(function (array $data) {
                [
                    'user_id' => $userId,
                    'domain_check_id' => $domainCheckId,
                    'message' => $message,
                    'categories' => $categories
                ] = $data;

                return new static(
                    user: User::find($userId),
                    domainCheck: DomainCheck::find($domainCheckId),
                    message: $message,
                    categories: $categories,
                );
            })->message(fn(self $notification) => $notification->message)
            ->description(fn(self $notification) => $notification->categories);
    }

    public function toArray($notifiable): array
    {
        $terms = is_array($this->domainCheck->terms) ? implode(', ', $this->domainCheck->terms) : $this->domainCheck->terms;
        $categories = is_array($this->domainCheck->categories) ? implode(', ', $this->domainCheck->categories) : $this->domainCheck->categories;
       
        return [
            'user_id' => $this->user->id,
            'domain_check_id' => $this->domainCheck->id,
            'message' => 'De domein checks zijn klaar voor: ' . $terms,
            'categories' => 'De volgende categorienen zijn uit gekozen: ' . $categories,
        ];
    }
Solution
i fixed it πŸ˜„ it was a stupid fault of me . I forgot to delete some old records i thought i did . Now it does the job just needed to edit the code for the id , It look like this now πŸ˜„

public function __construct(public User $user, public DomainCheck $domainCheck, public string $message, public string $categories)
    {
    }

    public function via($notifiable): array
    {
        return ['database'];
    }

    public static function toFilamentNotification(): FilamentNotification
    {
        return FilamentNotification::make()
            ->constructUsing(function (array $data) {
                [
                    'user_id' => $userId,
                    'domain_check_id' => $domainCheckId,
                    'message' => $message,
                    'categories' => $categories
                ] = $data;
                return new static(
                    user: User::find($userId),
                    domainCheck: DomainCheck::find($domainCheckId),
                    message: $message,
                    categories: $categories,
                );
            })->message(fn(self $notification) => $notification->message)
            ->description(fn(self $notification) => $notification->categories);
    }

    public function toArray($notifiable): array
    {
        $terms = is_array($this->domainCheck->terms) ? implode(', ', $this->domainCheck->terms) : $this->domainCheck->terms;
        $categories = is_array($this->domainCheck->categories) ? implode(', ', $this->domainCheck->categories) : $this->domainCheck->categories;
        return [
            'user_id' => $this->user->id,
            'domain_check_id' => $this->domainCheck->id,
            'message' => 'De domein checks zijn klaar voor: ' . $terms,
            'categories' => 'De volgende categorienen zijn uit gekozen: ' . $categories,
        ];
    }
Was this page helpful?