$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 (sheet: user/permission) that also returns an error message if the user has no permission.
If you want to check if the user has permission, use (sheet: user/can), 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
}