kodeine / laravel-acl

Light-weight role-based permissions system for Laravel 6+ built in Auth system.
MIT License
786 stars 216 forks source link

Error Call to undefined method Illuminate\Database\Query\Builder::assignPermission() #127

Open paragajency opened 8 years ago

paragajency commented 8 years ago

Hi @kodeine ,

I am getting " Call to undefined method Illuminate\Database\Query\Builder::assignPermission() "; while trying to assign permission to admin role.

I am using laravel 5.2

the permissions,roles,permission_role,permission_user,role_user tables are getting created in database. also Role is getting added in roles table successfully and
user permission is getting added successfully to permissions table

namespace App\Providers;

use Illuminate\Support\ServiceProvider; use Blade; use App\Role; use App\Permission; use Kodeine\Acl\Traits\HasPermission;

$role = new Role(); $roleAdmin = $role->create([ 'name' => 'Administrator', 'slug' => 'administrator', 'description' => 'Manage Administration Priviledes' ]);

$permission = new Permission(); $permUser = $permission->create([ 'name' =>'user', 'slug' => json_encode([ 'create' => true, 'view' => true, 'update' => true, 'delete' => true, 'view.phone' ]), 'description' => 'manage user permissions' ]); $roleAdmin = Role::first(); // administrator $roleAdmin->assignPermission('user');

I am getting " Call to undefined method Illuminate\Database\Query\Builder::assignPermission() "; for above last two lines of code

I have in config\acl.php return [ 'role' => 'kodeine\Acl\Models\Eloquent\Role', 'permission' => 'kodeine\Acl\Models\Eloquent\Permission', 'most_permissive_wins' => false, ];

And my vendor\laravel\frameworl\src\illuminate\Foundation\Auth\User.php is as follows

namespace Illuminate\Foundation\Auth; use Illuminate\Auth\Authenticatable; use Illuminate\Database\Eloquent\Model; use Illuminate\Auth\Passwords\CanResetPassword; use Illuminate\Foundation\Auth\Access\Authorizable; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; use Kodeine\Acl\Traits\HasRole; class User extends Model implements AuthenticatableContract,
CanResetPasswordContract { use Authenticatable, CanResetPassword, HasRole; }

anasibrahimgm commented 6 years ago

Hi there, Your Role Model should like like this:

/

some code

/ use Kodeine\Acl\Traits\HasPermission;

class Role extends Model { use HasPermission;

/*
*
#some code
*
*/

}