It seems like you're trying to retrieve the current active tab from a tabs form component and synchronize it with the URL parameter. To achieve this, you need to ensure that the tab state is being updated correctly when a new tab is selected and that the URL parameter is being read properly.
Here's a solution that might help you:
-
Make sure that the
persistTabInQueryStringmethod is working correctly. This method should update the URL with the active tab's identifier when a tab is changed. -
In your
mountmethod, read thetabparameter from the query string and set it as the active tab. -
In your
createmethod, you should be able to access the current tab from the$this->tabproperty if it's being set correctly.
Here's how you can modify your code:
public function mount(): void
{
$this->form->fill();
// Read the 'tab' parameter from the query string and set it as the active tab
$this->tab = request()->query('tab', $this->tab);
}
public function create(): void
{
// Now $this->tab should have the current active tab
dd($this->tab);
}
Make sure that your Tabs component is updating the URL correctly when a tab is changed. If the persistTabInQueryString method is not working as expected, you might need to manually update the URL when a tab is selected.
If you're using JavaScript to handle tab changes, you can update the URL using the history.pushState method:
function onTabChange(tabId) {
history.pushState({}, '', '?tab=' + tabId);
}
Remember to call this function whenever a tab is changed, passing the appropriate tab identifier.
If you're still having trouble, please provide more information about how your Tabs component works and how it's supposed to update the URL, so that a more precise solution can be given.