Check user has particular permission in Drupal 8

By Arun AK, 21 May, 2017

In drupal 8 we can use hasPermission() method to check user permission.

$account = \Drupal::currentUser();
$php_access = $account->hasPermission('use php for tracking visibility');

if(!$php_access) { // User has permission.
  // Write your code.
}