I am currently trying to assign any guest the role 'Guest' so that they can have permissions. I currently have the following code, which is apart of some middleware, this seems to be the wrong place to have it, I would assume there is a much better place, I have tried using a service provider, however I couldn't attach the group
if($this->auth->guest())
{
$user = new User();
$user->username = 'Guest';
$role = Role::where('name', '=', 'guest')
->with('perms')
->first();
$user->perms = new Collection();
$user->perms->add($role);
$perms = explode('|', $permissions);
foreach($user->perms as $p) {
foreach($p->perms as $pp) {
foreach($perms as $perm) {
if($perm === $pp->name)
return $next($request);
}
}
}
}
As you can see this is very specific to middleware, Ideally I want to attack the role at the first possible instance so it can be used in any part of the application