\Dvivier\SmarticopsUser

The main User class for Smarticops features.

Extends Authenticable which itself extends Eloquent User model.

So this class includs Authentication and Eloquent features.

To use a User class in your application, use the App\User class, which inherits this Smarticops\User class.

Summary

Methods
Properties
Constants
roles()
getRoles()
hasRole()
is()
scopeHavingRole()
permissions()
assignRole()
revokeRole()
revokeAllRoles()
fullName()
loadPermissions()
givePermission()
removePermission()
hasPermission()
isConfirmed()
No public properties found
No constants found
No protected methods found
$dates
$_permissions
$guarded
$fillable
$hidden
N/A
assignRolePermissions()
No private properties found
N/A

Properties

$dates

$dates : 

Type

$_permissions

$_permissions : array

Allows to temporarly store the permissions that a user has.

Avoids too many useless queries to the database

Type

array

$guarded

$guarded : 

Type

$fillable

$fillable : array

The attributes that are mass assignable.

Type

array

$hidden

$hidden : array

The attributes that should be hidden for arrays.

Type

array

Methods

roles()

roles() 

getRoles()

getRoles() : array

Get all the roles assigned to the user as an array of strings

Returns

array

hasRole()

hasRole(string  $roleName) : boolean

Checks if a user has a specific role

Parameters

string $roleName

The name of the role to test for, case sensitive.

Returns

boolean —

true if the user has the role, false otherwise.

is()

is(string  $roleName) : boolean

Just an alias for `hasRole()`.

Parameters

string $roleName

The name of the role to test for, case sensitive.

Returns

boolean —

true if the user has the role.

scopeHavingRole()

scopeHavingRole(mixed  $query,   $roleName) 

Defines a new query scope.

Allows to access directly all the users having a specific role.

Method written as described in the Laravel documentation.

Usage example : User->havingRole('Student');

Parameters

mixed $query
$roleName

permissions()

permissions() 

Pivot access to the users' permissions.

assignRole()

assignRole(\Dvivier\Smarticops\Role|string  $role = null, boolean  $givePermissions = false) : boolean

Assigns a role to the user.

Since a user can have multiple roles, the user keeps the roles it had before being assigned a new role. To remove a role from a user, use User->revokeRole(). If the user already has the roles, the method does nothing and true is returned.

Parameters

\Dvivier\Smarticops\Role|string $role

The Role instance, otherwise a string. Must exist before assigning.

boolean $givePermissions

If set to true, after assigning the role, the method will also give to the user all the permissions associated to the role.

Returns

boolean —

true if the role was succesfully added or was already assigned false if the assignation failed or if role doesn't exist

revokeRole()

revokeRole(  $role) : true

Removes the role from a user.

Parameters

$role

The role to revoke, object or string

Returns

true —

if (the user had the role AND it has not any more), false if the removal failed or the user didn't have the role

revokeAllRoles()

revokeAllRoles() 

Revokes all roles for this user.

fullName()

fullName() : string

The full name of the user.

Returns

string —

firstname + " " + last name

loadPermissions()

loadPermissions() : \Dvivier\Smarticops\Collection

Loads all the permissions associated to the user from the database to the Session To avoid too many requests to the DB

Returns

\Dvivier\Smarticops\Collection —

of Permissions

givePermission()

givePermission(  $permissionCode, boolean  $value = true) : boolean

Gives a specific permission to the user.

The permission must exist before giving it to the user. By default the permission is set to true, you may set it to false to explicitly mean that the user does NOT have that permission.

Parameters

$permissionCode
boolean $value

Returns

boolean —

true if the permission was successfully given to the user or if the user already had this permission false if the permission doesn't exist

removePermission()

removePermission(  $permissionCode) : true

Removes a Permission from a user, specifying the permission by its code.

Parameters

$permissionCode

$string

Returns

true —

if the permission was removed successfully, false if the permission does not exists, or if the user does not have the permission.

hasPermission()

hasPermission(  $permissionCode,   $fromDB = false) 

Tests if the user has a permission or not.

By default, the method looks only at the session where the permissions has been stored for the user currently logged in , Auth::user(). This allows to reduce the number of DB queries.

In most cases, there is no need to get info from database since the permissions are put in the session at login.

Pass true as 2nd argument if you're testing another user's permissions than the one who is logged in.

Parameters

$permissionCode

string the permission to test for

$fromDB

boolean (optional) whether or not do a request to the database

isConfirmed()

isConfirmed() : true

Checks if the user has confirmed his account by email or not.

Returns

true —

if the user has confirmed his account, false otherwise.

assignRolePermissions()

assignRolePermissions(  $role) 

For the given role, assign all the role permissions to the user.

Parameters

$role

Role