需要数据透视表的模型实例

I am currently trying to use this method

   public function givePermissionTo(Permission $permission)
     {
        return $this->permissions()->save($permission);
     }

So i can assign a permission to a role, for example:

$role->givePermissionTo(Permission::first());

However, what i get when trying to use that method is a bad method call exception.

My attempts to access that method were:

$role = Role::whereName('editor')->skip(1)->take(1)->get();

I have tried it in many other ways, but my problem is that i cannot get an instance of the Role Model, so i can access that method and give it the permission.

First of all, if you want to get a an exact role, you have to use first() method instead of get().
Try:

$role = Role::whereName('editor')->skip(1)->take(1)->first();

After assign the permission to the role you got:

$role->givePermissionTo(Permission::first());