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
How are you hiding the create action?
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;
}
})
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
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
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
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?
Yes it's possible because the livewire endpoint is different.
That was it, the request() is different when I click on the edit action
Why dont you reverse the logic and hide it by default. Have a condition to make it visible
Cool
Yeah, I'll try that. Thanks for the help !!
Welcome