Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

flashman's avatar

Simple FilamentPHP question of passing data to CreateRecord

Hi,

I have one page ClientItemsToPay that extends ManageRelatedRecords. That table is displaying unpayed services for client. Now I would like to check some of these items/rows and on click of button to send them to CreateRecord of InvoiceResource so these items appear as invoice items table?

  1. Do I need to redirect with route parameters, and encode json id's of selected items?
  2. Can I emit event or something?

How to do this, I am new to filament, tnx.

0 likes
4 replies
flashman's avatar

@mohamedtammam thanks, I know about bulk actions, but I need to pass selected row id's to another URL. For example:

  1. Items to pay: /client/1/items-to-pay
  2. Create invoice: /invoice/create

Redirect or pass data from client/1/items-to-pay -> invoice/create

Data should be array of selected item id's

Lopsum's avatar

You can pass the data to your InvoiceResource URL :

BulkAction::make('create_invoice')
                              ->action(function (Collection $records) {
                                  $ids = $records->pluck('id')->toArray();
                                  return redirect(InvoiceResource::getUrl('create', ['items' => $ids]));
                              }),

After that, you need to modify the mount() function in your CreateInvoice.php file :

public function mount(): void
    {
        if(request()->query('items')) {
          //If ever your items are a Model
            $items = Items::whereIn('id', request()->query('items'))->get(); 
         // Don't forget to initialize the proprety
            $this->items = $items;
        }
        $this->authorizeAccess();

        $this->fillForm();

        $this->previousUrl = url()->previous();
    }

After that, you should be able to use $this->items on your form schema 😇

coachben's avatar

Hi @mohamedtammam

Have you considered the use of ->html and ->url . And then you just pass the $record details to a route.

TextEntry::make('original_link') ->html() ->url(function (Model $record) { return $record->original_link; }),

Please or to participate in this conversation.