Keeping GET parameters through livewire ajax executions
I know this needed was already discussed in different moments because I saw the responses from that but I am not able to do this suggestions on my code.
I need to keep a GET parameters through livewire ajax executions to invoke different functions on form function.
At first I get the value by "request()->query('purchase_requisition_id');" but then I lose it.
The only way I found to do that is:
app\Filament\Resources\PurchaseOrderResource.php ->
Where I have to add the public property and mount function to replace the way I am getting and keeping the GET parameter? Thanks in advance!
Solution:Jump to solution
If you want to keep the
mount()
approach though, I think you can use a callback in your form schema()
:
```php
->schema(function ($livewire) {
if ($livewire->purchase_requisition_id) {
return [...9 Replies
You can't do this reliably in the static methods on your resource. I mean, you can find a hack but it's not designed for that.
Instead, use the
mount()
method on the Page component directly (e.g. EditPosts
)
Here's a quick example: https://discord.com/channels/883083792112300104/1132764689995145448/1132771508587077712Thanks @pboivin for your response. I added the public property and the mount function to my CreatePage but how to add fields to the form in base of the value of this public property ?
app\Filament\Resources\PurchaseOrderResource\Pages\CreatePurchaseOrder.php:
Not sure exactly how you plan on using this information but maybe something like this:
When the form is initialized, use the property as default value if possible.
Actually I need to create different fields based on the value of the variable. So in the $form I have added an IF to add fields to the schema based on value. So I'm thinking that what I need is outside the scope of the framework. I solved this situation as follows:
If this works for you then it's all that matters really 😄
It's an interesting use-case
Solution
If you want to keep the
mount()
approach though, I think you can use a callback in your form schema()
:
Why not just load each set of fields in its own group then use the injected $livewire to show or hide the group in visible(). Might be easier than worrying about ifs, etc.
Also looks like the handling of query strings changed in v3. https://livewire.laravel.com/docs/upgrading#url-query-string
Laravel
Upgrade Guide | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
Thanks both! I will try with Patrick suggestions first
@pboivin your suggestion works fine! I will use it to keep the mount function and not use custom function to get the GET parameter. Thanks a lot!
@awcodes thank you very much too!