GithubHelp home page GithubHelp logo

Comments (4)

klaravel avatar klaravel commented on July 28, 2024

@angallego Can you please show me your user and role model code ?

from ntrust.

angallego avatar angallego commented on July 28, 2024

Of course!
User.php
`<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Kodeine\Metable\Metable;
use Klaravel\Ntrust\Traits\NtrustUserTrait;

class User extends Authenticatable
{
use Metable, NtrustUserTrait;

protected $metaTable = 'users_meta';

protected static $roleProfile = 'user';

protected $table = 'users';

protected $fillable = ['first_name', 'last_name', 'email', 'phone', 'fax', 'username', 'password', 'status', 'token'];

protected $hidden = ['password', 'remember_token'];


public function groups()
{
  return $this->belongsToMany('App\UserGroup', 'user_user_group', 'user_id');
}

public function group()
{
  return $this->hasOne('App\UserGroup', 'id_extra', 'id');
}

public function userGroup()
{
  return $this->hasOne('App\UserUserGroup');
}

}`

Role.php
`<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Klaravel\Ntrust\Traits\NtrustRoleTrait;

class Role extends Model
{
use NtrustRoleTrait;

protected $table = 'roles';
protected $fillable = ['name', 'display_name', 'description'];

protected static $roleProfile = 'user';

}
`

Permission.php
`<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Klaravel\Ntrust\Traits\NtrustPermissionTrait;

class Permission extends Model
{
use NtrustPermissionTrait;

protected $table = 'permissions';
protected $fillable = ['name', 'display_name', 'description'];

protected static $roleProfile = 'user';

}
`

from ntrust.

klaravel avatar klaravel commented on July 28, 2024

Try below code in your config/ntrust.php file

<?php
return [
    'defaults' => [
        'profile' => 'user',
    ],
    'profiles' => [
        'user' => [
            'table' => 'users',
            'model' => App\User::class,
            'role' => App\Role::class,
            'roles_table' => 'roles',
            'permission' => App\Permission::class,
            'permissions_table' => 'permissions',
            'permission_role_table' => 'permission_role',
            'role_user_table' => 'role_user',
            'user_foreign_key' => 'user_id',
            'role_foreign_key' => 'role_id',
            'permission_foreign_key' => 'permission_id',
        ],
    ],
];

$role->roleProfile will be null. because of static variable.

If still not working then let me know what version of php are you using?

Check this code with tinker after get $role parame $perms = $role->perms

from ntrust.

klaravel avatar klaravel commented on July 28, 2024

@angallego Let me know if you still need help for this one.

I going to close this issue.

from ntrust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.