Skip to content

Instantly share code, notes, and snippets.

@yasaryousuf
Created May 13, 2018 11:06
Show Gist options
  • Save yasaryousuf/eff290fcfeee61a73012dba5785f3df2 to your computer and use it in GitHub Desktop.
Save yasaryousuf/eff290fcfeee61a73012dba5785f3df2 to your computer and use it in GitHub Desktop.
<?php
public function hasAnyRole($roles)
{
return null !== $this->roles()->whereIn('name', $roles)->first();
}
public function hasRole($role)
{
return null !== $this->roles()->where('name', $role)->first();
}
public function isSubscriber()
{
foreach ($this->roles()->get() as $role)
{
if ($role->name == 'Subscriber')
{
return true;
}
}
}
public function is($roleName)
{
foreach ($this->roles()->get() as $role)
{
if ($role->name == $roleName)
{
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment