laravel-doctrine / acl

ACL for Laravel Doctrine
http://laraveldoctrine.org/
MIT License
44 stars 30 forks source link

How to implement 'getPermissions' for Contracts\HasPermissions? #34

Closed vinigarcia87 closed 7 years ago

vinigarcia87 commented 7 years ago

Hi, I'm new on this lib and I have an issue making work.

I post my question on stackoverflow but I thought that I had to ask here too.

The code I have for my Role class is the following:

namespace App\Entities;

use Doctrine\ORM\Mapping as ORM;
use LaravelDoctrine\ACL\Contracts\Role as RoleContract;
use LaravelDoctrine\ACL\Contracts\HasPermissions as HasPermissionContract;
use LaravelDoctrine\ACL\Permissions\HasPermissions;

/**
 * @ORM\Entity
 * @ORM\Table(name="role")
 */
class Role implements
    RoleContract,
    HasPermissionContract
{
    use HasPermissions;

    /**
     * @ACL\HasPermissions
     */
    public $permissions;

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $name;

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

}

The documentation says to create a class Role that implements RoleContract. Later on, it says to use HasPermissions trait, that implements some methods from RoleContract.

But I got an error that says me I have to implement the 'getPermissions' method.

The documentation don't say what I have to implement here, or what I have to use to fix this. Can you please make it clear for me?

Thank in advance guys!

patrickbrouwers commented 7 years ago

You can return in ->getPermissions() however you stored your permissions.

In your cased it would be return $this-permissions;.