0

I installed a plugin in filament called "Ticketing": https://filamentphp.com/plugins/ticketing

filament has a method called afterCreate(), that's where I usually implement the notifications API, just as Filament docs mention:
https://filamentphp.com/docs/2.x/notifications/database-notifications

This is what I did so far:

$record = $this->record;

        // $recipients = User::pluck('name', 'id');

        // Send Database notification (within website)
        foreach ($recipients as $recipient) {
            $recipient->notify(
                Notification::make()
                    ->title('New Incident Created')
                    ->icon('heroicon-o-document-text')
                    ->body(
                        "**New incident: " .
                            __($record->ir_number->prefix ?? 'IR#' . str_pad($record->ir_number, 4, '0', STR_PAD_LEFT)) .
                            " of type {$record->caseTypeRelationship->name} was created by " . auth()->user()->name . "**"
                    )
                    ->actions([
                        Action::make('View')
                            ->url(TicketResource::getUrl('view', ['record' => $record])),
                    ])
                    ->toDatabase(),
            );
        };

Here is what the input looks like:

Select::make('assigned_to_id')
  ->label(__('Assign Ticket To'))
  ->hint(__('Key in 3 or more characters to begin search'))
  ->searchable()
  ->getSearchResultsUsing(function ($search) {
      if (strlen($search) < 3) {
        return [];
      }

      return config('filament-ticketing.user-model')::where('name', 'like', "%{$search}%")
        ->limit(50)
        // ->get()
        // ->filter(fn ($user) => $user->can('manageAssignedTickets', Ticket::class))
        ->pluck('name', 'id');
   })
    ->getOptionLabelUsing(fn ($value): ?string => config('filament-ticketing.user-model')::find($value)?->name)
    ->disabled($cannotAssignTickets),
    // ->hiddenOn('create')
    ]

How can I set $recipients to equal the selected user in the assign_to_id input?

Abdulrahman Mushref
  • 1,012
  • 2
  • 18
  • 40

1 Answers1

2

im new to filamentphp so please correct me if i;m wrong, maybe you know that $recipients need a collection not a builder. same as

User::where('id',1)->get() //is a builder

and

User::find(1) //is a collection

so in my case, I use this :

` $record = $this->record;

$assigned_to_id= $record->assigned_to_id;

        $recipient = User::find($assigned_to_id);
        Notification::make()
        ->title('New Incident Created')
                ->icon('heroicon-o-document-text')
                ->body(
                    "**New incident: " .
                        __($record->ir_number->prefix ?? 'IR#' . str_pad($record->ir_number, 4, '0', STR_PAD_LEFT)) .
                        " of type {$record->caseTypeRelationship->name} was created by " . auth()->user()->name . "**"
                )
                ->actions([
                    Action::make('View')
                        ->url(TicketResource::getUrl('view', ['record' => $record])),
                ])
        ->sendToDatabase($recipient);

`