Sentinel\Repositories\User\SentryUserRepository::store PHP Метод

store() публичный Метод

Store a newly created user in storage.
public store ( $data ) : Sentinel\DataTransferObjects\BaseResponse
Результат Sentinel\DataTransferObjects\BaseResponse
    public function store($data)
    {
        try {
            // Should we automatically activate this user?
            if (array_key_exists('activate', $data)) {
                $activateUser = (bool) $data['activate'];
            } else {
                $activateUser = !$this->config->get('sentinel.require_activation', true);
            }
            //Prepare the user credentials
            $credentials = ['email' => e($data['email']), 'password' => e($data['password'])];
            // Are we allowed to use usernames?
            if ($this->config->get('sentinel.allow_usernames', false)) {
                // Make sure a username was provided with the user data
                if (array_key_exists('username', $data)) {
                    $credentials['username'] = e($data['username']);
                }
            }
            // Attempt user registration
            $user = $this->sentry->register($credentials, $activateUser, $data);
            // If the developer has specified additional fields for this user, update them here.
            foreach ($this->config->get('sentinel.additional_user_fields', []) as $key => $value) {
                if (array_key_exists($key, $data)) {
                    $user->{$key} = e($data[$key]);
                }
            }
            $user->save();
            // If no group memberships were specified, use the default groups from config
            if (array_key_exists('groups', $data)) {
                $groups = $data['groups'];
            } else {
                $groups = $this->config->get('sentinel.default_user_groups', []);
            }
            // Assign groups to this user
            foreach ($groups as $name) {
                $group = $this->sentry->getGroupProvider()->findByName($name);
                $user->addGroup($group);
            }
            // User registration was successful.  Determine response message
            if ($activateUser) {
                $message = trans('Sentinel::users.createdactive');
            } else {
                $message = trans('Sentinel::users.created');
            }
            // Response Payload
            $payload = ['user' => $user, 'activated' => $activateUser];
            // Fire the 'user registered' event
            $this->dispatcher->fire('sentinel.user.registered', $payload);
            // Return a response
            return new SuccessResponse($message, $payload);
        } catch (UserExistsException $e) {
            // If the User is already registered but hasn't yet completed the activation
            // process resend the activation email and show appropriate message.
            if ($this->config->get('sentinel.require_activation', true)) {
                //Attempt to find the user.
                $user = $this->sentry->getUserProvider()->findByLogin(e($data['email']));
                // If the user is not currently activated resend the activation email
                if (!$user->isActivated()) {
                    $this->dispatcher->fire('sentinel.user.resend', ['user' => $user, 'activated' => $user->activated]);
                    return new FailureResponse(trans('Sentinel::users.pendingactivation'), ['user' => $user]);
                }
            }
            $message = trans('Sentinel::users.exists');
            return new ExceptionResponse($message);
        }
    }