EditAction enabling hidden CreateAction in headerActions

I know it sounds a bit confusing but I'll try my best to explain. I have a CreateAction as a headerAction of a table and it has the hidden function and when first loading the page the CreateAction is hidden which is what I want, however when I click on the EditAction the modal opens and the CreateAction button is visible which shouldn't happen. Is this a bug? Link to video: https://www.loom.com/share/140f468dde0c4f858f1e9f9c9f6fc9d2?sid=fd2e9f6d-2cc1-4a32-9753-ddaf2be27495
11 Replies
tim.lalev
tim.lalev4mo ago
How are you hiding the create action?
Renan Pereira
Renan Pereira4mo ago
CreateAction::make() ->icon('heroicon-c-plus') ->label('Adicionar') ->color('success') ->hidden(function () { if (!Auth::user()->can('edit_empresas')) { return true; } if (request()->routeIs('funcionarios.index')) { return true; } })
tim.lalev
tim.lalev4mo ago
That auth stuff belongs better in a policy and will probably solve that issue. Something weird is happening that re renders the the button Any js errors in console? May be livewire key mismatch
Renan Pereira
Renan Pereira4mo ago
Right, I'll think about replacing it later as better practice, but it isn't even entering this condition This is the condition it is returning as true if (request()->routeIs('funcionarios.index')) { return true; } No errors in the console
tim.lalev
tim.lalev4mo ago
Then it's possible for the Auth::user() to give you null for the subsequent request that is happening and that is why it never reaches the condition
Renan Pereira
Renan Pereira4mo ago
I removed the Auth verification to test if that was the issue, but it still remains Could it be that on the reaload the route is different somehow?
tim.lalev
tim.lalev4mo ago
Yes it's possible because the livewire endpoint is different.
Renan Pereira
Renan Pereira4mo ago
That was it, the request() is different when I click on the edit action
tim.lalev
tim.lalev4mo ago
Why dont you reverse the logic and hide it by default. Have a condition to make it visible Cool
Renan Pereira
Renan Pereira4mo ago
Yeah, I'll try that. Thanks for the help !!
tim.lalev
tim.lalev4mo ago
Welcome
Want results from more Discord servers?
Add your server