dcasia / resource-navigation-tab

Organize your resource fields into tabs.
MIT License
77 stars 9 forks source link

Hide/Show Tab #35

Closed ErenPhayte closed 1 year ago

ErenPhayte commented 3 years ago

Is there a way to hide/show tab based on rules i.e. permissions or any other rules based on the values of a Resource?

milewski commented 3 years ago

You can always do something like this:

class ExampleNovaResource extends Resource {

    public function fields(Request $request)
    {
        if($request->user()->can(.....)) {
            return [
                ResourceNavigationTab::make([ 'label' => 'Only for admin' ]),
            ];
        }

        return [
            ResourceNavigationTab::make([ 'label' => 'Public' ]),
        ];
    }

}
ErenPhayte commented 3 years ago

Thanks. But what if its needs to show or hide by Resource values I.e. I have Pages and you can clone them. Only for pages that have been cloned I want a tab that shows which pages were the clone (children parent relationship)

On Tue, 23 Feb 2021, 13:03 Rafael Milewski, notifications@github.com wrote:

You can always do something like this:

class ExampleNovaResource extends Resource {

public function fields(Request $request)
{
    if($request->user()->can(.....)) {
        return [
            ResourceNavigationTab::make([ 'label' => 'Only for admin' ]),
        ];
    }

    return [
        ResourceNavigationTab::make([ 'label' => 'Public' ]),
    ];
}

}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dcasia/resource-navigation-tab/issues/35#issuecomment-784118214, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKWBB2XLECX3ZL65HA5WFLTAODO5ANCNFSM4YCH4NJQ .

milewski commented 3 years ago

I think its still the same concept, you dynamically build the array of fields based on your condition.. if you need 3 tabs.. return 3 instances of ResourceNavigationTab .. so on..

milewski commented 1 year ago

The latest version respects the authorization of the fields, so besides the solution mentioned above the tab will also hide if the user inst allowed to see any of the fields contained within.