/** * is_admin Returns true if the logged in user is in group `Admin` * @return [boolean] */ private function is_admin() { try { // Find the Administrator group $admin = Sentry::findGroupByName('admin'); // Check if the user is in the admin group if ($this->user->inGroup($admin)) { // User is in admin group return true; } else { // User is not in Admin group return false; } } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { // echo 'User was not found.'; return false; } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { // echo 'Group was not found.'; return false; } }
/** * is_client Returns true if the logged in user is in group `Client` * @return [boolean] */ private function is_client() { try { // Find the Administrator group $client = Sentry::findGroupByName('Client'); // Check if the user is in the client group if ($this->user->inGroup($client) || $this->user->isSuperUser()) { // User is in Client group return true; } else { // User is not in Client group return false; } } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { // echo 'User was not found.'; return false; } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { // echo 'Group was not found.'; return false; } }
/** * 监听创建事件 */ public static function boot() { parent::boot(); self::creating(function ($user) { $primaryKey = $user->get_primary_key(); if (!isset($user[$primaryKey])) { $user[$primaryKey] = BaseModel::get_unique_id(self::$id_prefix); } return true; }); }
public function __construct() { parent::__construct(); }