klaravel / ntrust Goto Github PK
View Code? Open in Web Editor NEWRole-Based Permissions for Laravel 5.3 to 5.5 with multi user support.
License: MIT License
Role-Based Permissions for Laravel 5.3 to 5.5 with multi user support.
License: MIT License
Hi!
When I try to access the permissions of a role, show this error:
Class name must be a valid object or a string
$perms = $ role->perms()->get();
In fact, $role->roleProfile is null
BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::attachRole()
in
$user->attachRole($admin);
Hi,
This is not issue, i am asking you a suggestion.
my route:
Route::group(['middleware' => ['permission:roles']], function() { Route::resource("/roles", "RoleController"); });
In this above route working fine but, if a person do not have roles permission it redirects 404 page or dashboard page.
Controller level i can restrict and redirects to dashboard. But i can't understand how to write if condition in route level.
I am following the docs but I am after getting stuck.
After installing via composer and updating provider and alias if I run
$ php artisan ntrust:migration Admin
I get an error Class 'App\Admin' not found
So I $ php artisan create:model Admin
Do I need to manually add the relationships between admin, roles and users here? If so, what relationships or is that up to me?
Admin: belongsTo('App\User') ?
User: hasMany('App\Admin') ?
User: hasMany('App\Role') ?
Admin: hasMany('App\Role') ?
If I run $ php artisan ntrust:migration admin
here I can create Tables: admin_roles, admin_role_user, admin_permissions, admin_permission_role
but I try and migrate I get an error
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `admin_role_user` add constraint `admin_role_user_user_id_foreign` foreign key (`user_id`) references `admins` (`id`) on delete cascade on update cascade)
[PDOException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint `
Am I doing something wrong or are the docs missing something?
Only admin_roles & admin_role_user get migrated.
Hello, when i attach the one permission to user or set multi permission , i have one error , this my code:
$user->attachPermissions([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
or
$user->attachPermission(1);
May you help me ?
[BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::attachPermissio
ns()
Hi ,
ntrust package is really wonderful . but i have a small issue on this, i am getting below error when i am going to edit a role with added permissions.
{!! Form::select('permissions[]',$permissions,$role->permission->pluck('id'),['id'=>'multiple-checkboxes','multiple'=>true] ) !!}
Call to a member function pluck() on null (View: D:\projects\boom\resources\views\roles\edit.blade.php)
Please help me is am doing any this wrong to call added permissions.
When deleting role record, an error occurred.
FatalThrowableError in NtrustRoleTrait.php line 95:
Using $this when not in object context
After I check the line 95 of NtrustRoleTrait.php, seems you are calling $this
within the static method.
Any solution for that?
Hi, I am getting this error when trying to determine a user's role running the following code:
$user->hasRole('admin');
I have 2 role types, 'user' and 'admin' and I'm not using permissions.
I am sure this is something I am doing incorrectly but since I saw the last thread was left unopen I thought I should post.
User Model:
FatalErrorException in Permission.php line 8:
Trait 'Klaravel\Ntrust\Traits\NtrustPermissionTrait' not found
change trait NntrustPermissionTrait to NtrustPermissionTrait
I'm using Laravel 5.3 multiauth guards.
I have edited ntrust.php
in config
directory.
When I run php artisan ntrust:migration admin
or php artisan ntrust:migration user
it creates migrations with not admin_user_id
or site_user_id
it creates with default value user_id
.
Same with role_id
and permission_id
@ROLE('admin')
get ErrorException
Parse error: syntax error, unexpected ''admin'' (T_CONSTANT_ENCAPSED_STRING) (View: ...
I found this error when trying to delete a model with SoftDeletes.
This property is not declared in the model documentation and it refers to the boot
method in the NtrustUserTrait
.
public static function boot()
{
parent::boot();
static::deleting(function($user) {
if (!method_exists(Config::get('ntrust.profiles.' . self::$staticRoleProfile . '.model'), 'bootSoftDeletes')) {
$user->roles()->sync([]);
}
return true;
});
}
However, it works just by adding the property with the same profile as the non static $roleProfile
protected $roleProfile = 'user';
protected static $staticRoleProfile = 'user';
Should i keep the model like that? or is there any other workaround?
I saw this issue closed and the user said he just restarted the configuration, but it doesn´t work for me
issue/20
This problem happens in the current state of master branch.
Here is the stack trace:
1. in Builder.php line 2448
2. at Builder->__call('restored', array(object(Closure)))
3. at call_user_func_array(array(object(Builder), 'restored'), array(object(Closure))) in Builder.php line 1465
4. at Builder->__call('restored', array(object(Closure)))
5. at call_user_func_array(array(object(Builder), 'restored'), array(object(Closure))) in Model.php line 3551
6. at Model->__call('restored', array(object(Closure)))
7. at call_user_func_array(array(object(User), 'restored'), array(object(Closure))) in Model.php line 3565
8. at Model::__callStatic('restored', array(object(Closure))) in NtrustUserTrait.php line 81
9. at User::bootObservers() in NtrustUserTrait.php line 45
10. at User::boot() in Model.php line 296
11. at Model->bootIfNotBooted() in Model.php line 277
12. at Model->__construct() in EloquentUserProvider.php line 130
13. at EloquentUserProvider->createModel() in EloquentUserProvider.php line 47
14. at EloquentUserProvider->retrieveById('1') in SessionGuard.php line 132
15. at SessionGuard->user() in GuardHelpers.php line 35
16. at SessionGuard->authenticate() in AuthManager.php line 294
17. at AuthManager->__call('authenticate', array()) in Authenticate.php line 57
18. at Authenticate->authenticate(array()) in Authenticate.php line 41
19. at Authenticate->handle(object(Request), object(Closure)) in Pipeline.php line 137
20. at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
21. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
22. at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
23. at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
24. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
25. at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
26. at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
27. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
28. at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
29. at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
30. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
31. at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
32. at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
33. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
34. at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
35. at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
36. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
37. at Pipeline->then(object(Closure)) in Router.php line 644
38. at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
39. at Router->dispatchToRoute(object(Request)) in Router.php line 596
40. at Router->dispatch(object(Request)) in Kernel.php line 267
41. at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
42. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Debugbar.php line 51
43. at Debugbar->handle(object(Request), object(Closure)) in Pipeline.php line 137
44. at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
45. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
46. at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
47. at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
48. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
49. at Pipeline->then(object(Closure)) in Kernel.php line 149
50. at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
51. at Kernel->handle(object(Request)) in index.php line 53
52. at require_once('/home/aterbonus/prueba/public/index.php') in server.php line 21
The problem is caused by this when the user model doesn't have the SoftDeletes
trait.
Is a requirement to use ntrust to have the SoftDeletes
trait in the user model?
why when i run in terminal
php artisan ntrust:migration user
it always throw an error like this:
[Symfony\Component\Debug\Exception\FatalThrowableError] Parse error: syntax error, unexpected '*', expecting function (T_FUNCTION)
anyone can help me?
After installed, some tables are added to the database, but no admins. I see \config\ntrust.php has
'table' => 'admins',
model' => 'App\Models\Admin',
In your migrations file xxx_admin_ntrust_setup_tables.php, there is admin_permission_role, admin_permissions, admin_role_user, admin_roles. But no admins ??
is it possibile migrate an existing project from Zizaco/entrust to klaravel/ntrust?
As mentioned in readme.md, I updated User model with protected static $roleProfile = 'user';
but it's not present in the user object. If I use without static, the variable is present in user object.
Since the static variable is not working I get Class name must be a valid object or a string error. Laravel version is 5.3.29
Please advice
I have the ntrust.php in the config folder, but i am still getting this error.
I'm trying to remove users from database, so in my controller I do:
$ User = User :: find ($ id);
$ User-> delete ();
But I am always getting the error: "Access to undeclared static property User :: $ staticRoleProfile"
Someone can help me? I'm very noob with PHP / Laravel (I do not know if it's a complex problem or not, sorry).
Thanks a lot.
Is this package support Single Sign On with Laravel Passport?
Seems similar to laravel in-built authorization.
What are the pros of this package versus built-in functionalities?
https://laravel.com/docs/5.4/authorization
I have existing role, and I'm trying to save that role to user
$user = User::find(1);//working
$role = Role::where('id', '=', 1)->first();//working
$user->attachRole($role);
After update to new version, i get this
ErrorException in \vendor\klaravel\ntrust\src\Ntrust\Traits\NtrustUserTrait.php line 14:
Access to undeclared static property: App\User::$roleProfile
(View: ..\resources\views\sections\menu.blade.php)
in view i use
@role('admin')
@endrole
@role(['creator', 'moderator'])
@endrole
@role('user')
@endrole
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.