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 App\Models;
use App\Models\Formatters\Formatter;
use Illuminate\Foundation\Auth\User 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 \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function account()
{
return $this->hasOne(Account::class);
}
/**
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function referrer()
{
return $this->belongsTo(User::class);
}
/**
* Users, referred by current user (referees)
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
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);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire