passing action arguments into nested actions

I have an action with footer actions. In those footer actions I need $arguments from the mountUsing on the parent. Not sure how to obtain those arguments in the child?
Solution:
```php public function dayAction(): Action { return Action::make('day') ->label('Day Clicked')...
Jump to solution
12 Replies
Jamie Cee
Jamie CeeOP5w ago
public function testAction(): Action
{
return Action::make('day_action')
->label('Day Clicked')
->modalHeading('Choose an action')
->modalSubmitAction(false) // disable default "Save" button
->modalFooterActionsAlignment('center')
->modalWidth('md')
->mountUsing(function (array $arguments) {
dd($arguments);
})
->modalFooterActions([
// 1. View Day button

// 2. Add Availability button
Action::make('addAvailability')
->label('Add Availability')
->color('success')
->mountUsing(function (array $arguments, Form $form) {
// Prefill if needed
dd($this->mountedActionArguments());
$form->fill([
'start_date' => $arguments['date'] ?? now()->toDateString(),
'end_date' => $arguments['date'] ?? now()->toDateString(),
]);
})
->form($this->getAvailabilityForm()) // extract your giant schema into a helper
->action(function (array $data) {
// Save the availability here
// dd($data);
}),
]);
}
public function testAction(): Action
{
return Action::make('day_action')
->label('Day Clicked')
->modalHeading('Choose an action')
->modalSubmitAction(false) // disable default "Save" button
->modalFooterActionsAlignment('center')
->modalWidth('md')
->mountUsing(function (array $arguments) {
dd($arguments);
})
->modalFooterActions([
// 1. View Day button

// 2. Add Availability button
Action::make('addAvailability')
->label('Add Availability')
->color('success')
->mountUsing(function (array $arguments, Form $form) {
// Prefill if needed
dd($this->mountedActionArguments());
$form->fill([
'start_date' => $arguments['date'] ?? now()->toDateString(),
'end_date' => $arguments['date'] ?? now()->toDateString(),
]);
})
->form($this->getAvailabilityForm()) // extract your giant schema into a helper
->action(function (array $data) {
// Save the availability here
// dd($data);
}),
]);
}
Trimmed for character limit
Jamie Cee
Jamie CeeOP5w ago
Ah, that could be it. my plan is having a click event that opens a modal, im shown 2 buttons, 1 to view the date I clicked in a calendar, and another that would update the modal form or redirect to another modal form to submit hours I just couldnt get the arrguments passed into the action to go into the footer action
LeandroFerreira
yes, I think makeModalSubmitAction. Try it
Jamie Cee
Jamie CeeOP5w ago
Just on my lunch break now, will be back on in a few hours to give it a try, Ill leave this ticket open for now. Thank you 🙂
LeandroFerreira
no no, try it right now just kidding 😅 if it doesn't work, tag me and share the code that you are using ✌️
Jamie Cee
Jamie CeeOP5w ago
Yes boss! 🫡 🤣 Got like 3 projects on the go right now, its hectic. And I need to speak to the boss about alocating time to update our boilerplate to v4 - im running out of energy 🤣 From what I can see, that isnt working -> Is this just expecting data from the initial action? Where im calling the action
$this->mountAction('test', ['date' => $carbon, 'record' => $this->instructor->getKey()]); // Example time, adjust as needed
$this->mountAction('test', ['date' => $carbon, 'record' => $this->instructor->getKey()]); // Example time, adjust as needed
Then I need those keys/values in the footer action
LeandroFerreira
Could share the whole code on gist?
Jamie Cee
Jamie CeeOP5w ago
So I managed to add record, but still cant get the initial argument in. I can only share bits of it due to NDA I've sent it via DM
Solution
LeandroFerreira
public function dayAction(): Action
{
return Action::make('day')
->label('Day Clicked')
->modal()
->modalSubmitAction(false)
->extraModalFooterActions(function (Action $action): array {
return [
Action::make('addAvailability')
->color('success')
->fillForm(fn (): array => [
'date' => $action->getArguments()['date'] ?? null,
'user' => $action->getArguments()['record'] ?? null,
])
->form([
TextInput::make('date'),
Select::make('user')
->options([
1 => 'User 1',
2 => 'User 2',
]),
])
->action(function (array $data) {
dd($data);
}),
];
});
}
public function dayAction(): Action
{
return Action::make('day')
->label('Day Clicked')
->modal()
->modalSubmitAction(false)
->extraModalFooterActions(function (Action $action): array {
return [
Action::make('addAvailability')
->color('success')
->fillForm(fn (): array => [
'date' => $action->getArguments()['date'] ?? null,
'user' => $action->getArguments()['record'] ?? null,
])
->form([
TextInput::make('date'),
Select::make('user')
->options([
1 => 'User 1',
2 => 'User 2',
]),
])
->action(function (array $data) {
dd($data);
}),
];
});
}
and use $this->mountAction('day', ['date' => now(), 'record' => 1])
LeandroFerreira
don't forget this: The method must share the exact same name as the action, or the name followed by Action
Jamie Cee
Jamie CeeOP5w ago
So that did show the form, but when I try to use a function that returns form components, it doesnt show?
public function dayAction(): Action
{
return Action::make('day')
->label('Day Clicked')
->modal()
->modalSubmitAction(false)
->extraModalFooterActions(function (Action $action): array {
return [
Action::make('addAvailability')
->color('success')
->record($this->instructor)
->fillForm(fn(): array => [
'start_date' => $action->getArguments()['date'] ?? null,
])
->form(
[self::getInstructorAvailabilityFormComponent()]
)
->action(function (array $data) {
// dd($data);
}),
];
});
}
public function dayAction(): Action
{
return Action::make('day')
->label('Day Clicked')
->modal()
->modalSubmitAction(false)
->extraModalFooterActions(function (Action $action): array {
return [
Action::make('addAvailability')
->color('success')
->record($this->instructor)
->fillForm(fn(): array => [
'start_date' => $action->getArguments()['date'] ?? null,
])
->form(
[self::getInstructorAvailabilityFormComponent()]
)
->action(function (array $data) {
// dd($data);
}),
];
});
}
And the snippet of the function
public static function getInstructorAvailabilityFormComponent(): Component
{
return Forms\Components\Section::make('Instructor Availability')
->description('Set available working hours for instructors')
->schema([
Forms\Components\Repeater::make('instructor_availabilities')
->relationship('instructorAvailabilities', function ($query) {
return $query->where('auto_generated', false);
})
->collapsible()
->label('Availability Periods')
->collapsed()
->collapsible()
->schema([
public static function getInstructorAvailabilityFormComponent(): Component
{
return Forms\Components\Section::make('Instructor Availability')
->description('Set available working hours for instructors')
->schema([
Forms\Components\Repeater::make('instructor_availabilities')
->relationship('instructorAvailabilities', function ($query) {
return $query->where('auto_generated', false);
})
->collapsible()
->label('Availability Periods')
->collapsed()
->collapsible()
->schema([
Surely its not because im using sections and grids etc? Oh, apparently it is, but also made me realise that I dont even need the form im trying to use 🤣 So your solution was spot on

Did you find this page helpful?