Open r4bick opened 10 months ago
Perhaps you're talking about this - https://orchid.software/en/docs/modals/#asynchronous-data-loading
In general everything is similar to the usual work with data in a Screen, only for the Screen the data is prepared in query
, and for the modal in the method indicated in ->async
and then this data can be accessed in modal layouts..
How could i decide the following problem:
In UserEditLayout i need to get access to User model that i get in asyncGetUser method to render layout depends on its state?
class UserListScreen extends Screen
{
public function query(): iterable
{
return [
'users' => User::with('roles')
->paginate(),
];
}
public function layout(): iterable
{
return [
UserFiltersLayout::class,
UserListLayout::class,
Layout::modal('asyncEditUserModal', UserEditLayout::class)
->async('asyncGetUser'),
];
}
public function asyncGetUser(User $user): iterable
{
return [
'user' => $user,
];
}
}
class UserEditLayout extends Rows
{
public function fields(): array
{
// need to access to User model
return [
];
}
}
I have the same question. The documentation shows how to pass a variable to a modal, but there is no clear example how to refer to the passed variable from within the modal layout.
Just had the same issue and the easiest solution is to just use request('my-parameter-key')
inside of the Modal component class. Because the async request is a normal route call, this works perfectly fine. :)
hope this helps.
@SimonErich you saved my day! That wasn't the most obvious solution but it worked well. @tabuna would you mind reflecting this case in the documentation?
Is your feature request related to a problem? Please describe. There is no possibility to get parameters that getting by async request in during specify modal layouts.
Describe the solution you'd like To have a method to get access to these params for more flexibility. Now we can get only access to result of query method.