Snippets for Laravel
Some usefull and often used snippets of code for Laravel framework or any other php framework with similar design.
List will be extended in future.
|* Check whether user has permission to do something. Comparison is done|
|* with bitwise operations. Column name in roles table could be specified|
|* as second parameter.|
|* @uses User::role() where role() should be relationship with Role::class|
|* @param int $permission|
|* @param string|null $name|
|* @return bool|
|public function hasPermission($permission, $name = null)|
|$permissionName = isset($name) ? $name : 'permission';|
|$result = $this->role->$permissionName & $permission;|
|return ($result == $permission)|
|? true : false;|