コード例 #1
0
 /**
  * Get User's session
  *
  * @param string $userKey
  * @param bool $create
  * @return Member
  */
 private static function getUser($userKey = null, $create = false)
 {
     $session = session();
     $user = null;
     if ($userKey) {
         $user = Member::where(['key' => $userKey])->first();
         if (!$user && $create && Member::getAutoLicense(Site::getName())) {
             $user = Member::create(['key' => $userKey, 'first_name' => Site::getName() . ' user']);
             $user->createAutoLicense(Site::getName());
         }
         if ($user) {
             $session->put('tool.user', $user->key);
         }
     } else {
         if ($session->has('tool.user')) {
             $userKey = $session->get('tool.user');
             $user = Member::where(['key' => $userKey])->first();
         }
     }
     return $user;
 }