Bind $record in a custom action
Giving the following component:
How can i make the repeater know that the record is the $record resolved on mount?
Made a little repro repo with everything set up, no need for migrations and seeders
https://github.com/saade/filament-lab/tree/action-record
Solution:Hey @Dan Harrin, is this something you could still work on? Or perhaps point me in the right direction. Thanks!
I think https://discord.com/channels/883083792112300104/1176627389967646791/1176895501732413460 got implemented since when i've created this thread, the issue seems to be solved, thank you!...Jump to solution
46 Replies
i usually use
fillForm
Yeah but i need the actual record in this case, because of the
->relationship()
Made a little repro repo with everything set up, no need for migrations and seeders
https://github.com/saade/filament-lab/tree/action-recordit would be nice if you could do
->record(fn ($arguments) => Author::find($arguments['id']))
not sure if thats possible, or how difficult it would be to implementmaybe this?
it will only work on the first lw request when the modal opens
hum..
Hi Leandro, thanks for your response, the problem is exactly what Dan said
so.. this is even possible?
this would help
$arguments = Arr::last($livewire->mountedActionsArguments);
i think this would need to be the syntax
its probably possible, yes
does record() accept closures?
ummm, not sure I was using fillForm
yup
record(Model | Closure | null $record):
yes, but the $arguments is not resolved there
i think thats the problem
and i dont know how to PR a "fix" for this
i wonder why
track down where ->arguments() are set
it will not work after the first request, like adding a repeater item
$arguments is available in fillForm() anyway
the problem is not filling the form, its that the repeater does not know what $record to apply the relationship
it tries to load the ->relationship() on null
Resolving
$arguments
in ->record()
is easy as adding it to the resolve function, but work only on first request1) arguments probably need to be passed in at the StaticAction level, or wherever the HasArguments trait is applied
2) after the first request, ->arguments() have to be passed back into the object, probably in
getCachedAction()
or something?1) arguments is properly resolved without my addition to the Action class, the problem is in the second request, my bad
2) that's a little bit beyond my knowledge, i can open an issue referencing this thread if that's ok to you
dont worry about the issue. i'll spend 10 minutes looking into it
thank you Dan ๐
there's a repro repo in this thread, its all set up, including the database.sqlite
let me try it
yes! it works!! thank you
let me try the fix in the adjacency-list plugin
will test this hopefully will fix
https://discord.com/channels/883083792112300104/1176664503149137940/1176664503149137940
too ๐
it works on the example i gave (using the actions packages on a lw compoennt), but i'm not sure this works while using inside a custom form component.
do you see anything wrong here?
https://github.com/saade/filament-adjacency-list/blob/feat/relationships/src/Forms/Components/Actions/EditAction.php#L58
the code i added before doesnt run for form component actions
the $record i'm giving there is the right model, but the action thinks i'm refering to the form record (not the one i'm passing)
if you can make a super simple reproduction for form component actions i will look into it
sure mate, thank you
Hi mate, here's the repo with everything you need, just clone and run, database included.
Go to the Authors edit page to read the problem description.
https://github.com/saade/filament-lab/tree/action-record
please use the
action-record
branchbtw i havent forgotten, just been super busy
all good
SolutionHey @Dan Harrin, is this something you could still work on? Or perhaps point me in the right direction. Thanks!
I think https://discord.com/channels/883083792112300104/1176627389967646791/1176895501732413460 got implemented since when i've created this thread, the issue seems to be solved, thank you!
Hey, I think you can do this (remove
->relationship('chapters')
in the AuthorResource)
The problem is that
$this->getRecord()
resolves to the Author (resource) not the Book (relation of the author) even if its parent container (the adjacency list container) is bound to the correct model.
Configuring an action with$action->record(Book)
, the repeater inside the form of the action should use the record from the action (Book), not from the resource (Author).
Also, its a plugin so i can't simply hard-code that on the codebase, but thanks anyway.$repeater->model($this->getRecord())
Isn't $this->getRecord()
resolving the Book model at this point?
Also, its a plugin so i can't simply hard-code that on the codebase
understoodNope, the User is resolved at this point
the thing is that
$action->record(Book)
is doing nothing, the record is still the resource form recordoh,
$this->getRecord()
yes this is the book record.
but did you tried to "Add to chapters"?yes, I'm saving it manually
take a look
what the actual fuck ๐คจ
using only that?
I'll send a PR
cool, thanks!