Skip to content

Instantly share code, notes, and snippets.



Last active Jun 18, 2019
What would you like to do?
Usefull and often used snippets of code for Laravel or any other php application with similar design.

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment