Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide search and create buttons on panel #252

Closed
thegregthomp opened this issue Aug 27, 2018 · 10 comments
Closed

Hide search and create buttons on panel #252

thegregthomp opened this issue Aug 27, 2018 · 10 comments

Comments

@thegregthomp
Copy link

Is it possible to hide these tools for a relation within a resource?
screen shot on 2018-08-27 at 11_57_08

@poxin13
Copy link

poxin13 commented Aug 27, 2018

You can create a policy to hide resource actions https://nova.laravel.com/docs/1.0/resources/authorization.html#policies

@thegregthomp
Copy link
Author

Thanks, this a good way of doing it. Preferably, I'd like to disable them for all users of any level but this may have to do.

@poxin13
Copy link

poxin13 commented Aug 27, 2018

All users would be a Policy defined as

public function create()
    {
        return false;
    }

@lucasromanojf
Copy link

For search, you can add the following to your Resource:

public static function searchable()
{
    return false;
}

Or give $search an empty array

@boyfromhell
Copy link

Add this to resource:

public static function authorizedToCreate(Request $request)
    {
        return false;
    }
        public function authorizedToDelete(Request $request)
    {
        return false;
    }

    public function authorizedToUpdate(Request $request)
    {
        return false;
    }
public static function searchable()
{
    return false;
}

@skalero01
Copy link

What if i want to hide the button only on the index page and not on the view page? I tried with the authorizedToCreate function but it works only the first time is loaded, after that it doesnt enter to the function anymore.

@MHassanSaqib
Copy link

What if i want to hide the button only on the index page and not on the view page? I tried with the authorizedToCreate function but it works only the first time is loaded, after that it doesnt enter to the function anymore.

Did you find any solution for this scenario?

@skalero01
Copy link

What if i want to hide the button only on the index page and not on the view page? I tried with the authorizedToCreate function but it works only the first time is loaded, after that it doesnt enter to the function anymore.

Did you find any solution for this scenario?

Nope :/

@azariah001
Copy link

azariah001 commented Aug 2, 2021

This isn't a real solution. But..... because there doesn't seem to be a view dependant permissions way of governing the create button, ie. a permission that says for the create permission when viewing this parent class return no, all others yes. I think if you were to handle it with permissions that would be the way to do it. Alternatively and IMO this should already be a thing, HasMany::make() should have a ->canCreate(false) option. But that failing, here's some CSS.

div[dusk="parent-class-detail-component"] div[dusk="has-many-child-class-index-component"] a[dusk='create-button'] {
  display: none;
}

Credit for the concept here: https://vander.host/knowledgebase/software-development/using-css-selectors-to-hide-button-in-laravel-nova/

Obviously, this is by-passable security-wise, however, I don't want to outright block the creation of new line items in the HasMany child class that references this class... I just want to block attempting to create them from this class because there's a dual belongs to relationship on the child class and the other class is authoritative, and can, depending on the users access level, dictate what entries can and can't be selected from the second belongsto class.

@ekazda
Copy link

ekazda commented Jan 20, 2024

For search, you can add the following to your Resource:

public static function searchable()
{
    return false;
}

Or give $search an empty array

The searchable() function is effective in making the search box disappear. However public static $search = []; still makes the search box appear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants