Skip to content

Instantly share code, notes, and snippets.

@silencesys
Last active June 18, 2019 09:25
Show Gist options
  • Save silencesys/5ad9403d2afa7a3359f2b7e299f8c97c to your computer and use it in GitHub Desktop.
Save silencesys/5ad9403d2afa7a3359f2b7e299f8c97c to your computer and use it in GitHub Desktop.
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.

<?php
/**
* 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