# Basic Usage

Follow the steps below to use the package

# Register acl menu

If you need the Roles and Permissions menu, you should register its tool in NovaServiceProvider

    use Masoudi\NovaAcl\Tools\RegisterAclMenu;
    
    ...
    /**
     * Get the tools that should be listed in the Nova sidebar.
     *
     * @return array
     */
    public function tools()
    {
        return [
            RegisterAclMenu::make(),
        ];
    }
    ...

# Authorize nova resources

By default, Laravel Nova uses Policy based authorization for Nova resources. If you are using the Spatie Permission library, it is very likely that you would want to swap this out to permission based authorization without the need to define Authorization policies.

To do so, you can use the InteractsWithACL trait and implement ACL interface in Nova resource class like so

use Masoudi\NovaAcl\Support\Contracts\ACL;
use Masoudi\NovaAcl\Support\InteractsWithACL;

class Post extends Resource implements ACL 
{
    use InteractsWithACL;
    
    /**
    * Permissions for abilities
    *
    * @return array
    */
    public static function permissionsForAbilities(): array
    {
        return [
            'all' => "manage posts",
        ];
    }
    
}

The example above means that all actions on this resource can be performed by users who have the "manage posts" permission.

You can also define separate permissions for each action like so

    /**
    * Permissions for abilities
    *
    * @return array
    */
    public static function permissionsForAbilities(): array
    {
        return [
            'viewAny' => 'view posts list',
            'view' => 'view post',
            'create' => 'create post',
            'update' => 'update post',
            'delete' => 'delete post',
            'restore' => 'restore post',
            'forceDelete' => 'forceDelete post',
            'addAttribute' => 'add post attributes',
            'attachAttribute' => 'attach post attributes',
            'detachAttribute' => 'detach post attributes',
        ];
    }

# Relationships

To allow your users to specify a relationship on your model, you will need to add another permission on the Model. For example, if your Post belongs to User, add the following permission on app/Nova/User.php

use Masoudi\NovaAcl\Support\Contracts\ACL;
use Masoudi\NovaAcl\Support\InteractsWithACL;

class User extends Resource implements ACL 
{
    use InteractsWithACL;
    
    /**
    * Permissions for abilities
    *
    * @return array
    */
    public static function permissionsForAbilities(): array
    {
        return [
            'addPost' => 'add user on posts'
        ];
    }
}