assign and return specific data based on user role

I like to understand how I can assign each user who has the role we say that each agent with its own interface, indeed I am applying a solution which set up a system in which an administrator creates a new user with the agent role, an agent can create users with the user role, so we suppose that an admin creates 2 agents: Agent A and agent B each agent accesses the same interface but each one has its own users, I don’t like to return all the users of the database in the interface of all the agents, so if agent A is authenticated the interface retrieves only the users who are added by agent A and the same thing for agent B is there a solution? im in laravel 5 here is mu User.php model

namespace AppModels;

use AppModelsFormattersFormatter;
use IlluminateFoundationAuthUser as Authenticatable;

class User extends Authenticatable
{




const ROLE_USER = 'USER';
const ROLE_ADMIN = 'ADMIN';




/**
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'last_login_from', 'role', 'status', 'last_login_at', 'referrer_id'
];

/**
*
*
* @var array
*/
protected $hidden = [
'password', 'remember_token', 'status', 'role', 'last_login_from', 'referrer_id', 'referrer', 'totp_secret'
];




/**
* User account
*
* @return IlluminateDatabaseEloquentRelationsHasOne
*/
public function account()
{
return $this->hasOne(Account::class);
}

/**

*
* @return IlluminateDatabaseEloquentRelationsBelongsTo
*/
public function referrer()
{
return $this->belongsTo(User::class);
}

/**
* Users, referred by current user (referees)
*
* @return IlluminateDatabaseEloquentRelationsHasMany
*/
public function referees()
{
return $this->hasMany(User::class, 'referrer_id');
}



/**
* User games
*
* @return $this
*/
public function games()
{
return $this->hasManyThrough(Game::class, Account::class)->where('status', Game::STATUS_COMPLETED);
}

/**
*
* @param $role
* @return bool
*/
public function hasRole($role)
{
return isset($this->role) && $this->role == $role;
}

public static function roles()
{
return [ self::ROLE_USER, self::ROLE_ADMIN];
}


/**
*
*/
public function admin()
{
return $this->hasRole(self::ROLE_ADMIN);
}



}

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/38P3tLD
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.