$user->cannot($event, $args = [])

Returns true if the user has no permission for the specified event

  • since: Kirby 2.4.0
  • $event (Event/string)
    Event object or a string with the event name
  • $args (mixed)
    Additional arguments for the permission callbacks
  • return (boolean)

There is also $user->permission($event, $args = []) that also returns an error message if the user has no permission.
If you want to check if the user has permission, use $user->can($event, $args = []), which otherwise does the same.

Example

$user = site()->user();
if(!$user) throw new Exception('No user is logged in.');

if($user->cannot('myplugin.permission', ['arg1', 'arg2'])) {
  // user has no permission
} else {
  // user has permission
}

Is something missing or incorrect? Edit this page on Github…