Search code examples
laravellaravel-nova

how to remove all checkboxes from resource list in laravel nova?


I have a laravel nova app. Like other nova app on resource list it shows a checkbox before every rows. and a option of select all.

Here is the screenshot of those checkboxes

I want to remove those checkboxes from the resource list.

Thanks.


Solution

  • As described in comments above, the cleanest way will be limiting user permissions. Otherwise, there are some hacky ways to try:

    1. Empty actions

    If you resource has no actions, then in your resource file override availableActions method:

    /**
     * Get the actions that are available for the given request.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return \Illuminate\Support\Collection
     */
    public function availableActions(NovaRequest $request)
    {
        return [];
    }
    

    2. Hiding with css.

    Put this in custom tool, or override layout.blade.php.

    EDIT Found a better way of hiding with css thanks to @Max's comment

    div[dusk="products-index-component"] div[dusk="select-all-dropdown"],
    div[dusk="products-index-component"] .table td:first-child,
    div[dusk="products-index-component"] .table th:first-child {
      display: none !important;
    }
    

    3. Custom resource-index component.

    Create custom tool and override /nova/resources/js/views/Index.vue. This is where checkbox showing logic goes on.

    /**
     * Determine whether to show the selection checkboxes for resources
     */
    shouldShowCheckBoxes() {
      return (
        Boolean(this.hasResources && !this.viaHasOne) &&
        Boolean(
          this.actionsAreAvailable ||
            this.authorizedToDeleteAnyResources ||
            this.canShowDeleteMenu
        )
      )
    },