Cartalyst\Sentinel\Sentinel::register PHP Метод

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

Registers a user. You may provide a callback to occur before the user is saved, or provide a true boolean as a shortcut to activation.
public register ( array $credentials, Closure | boolean $callback = null ) : Cartalyst\Sentinel\Users\UserInteface | boolean
$credentials array
$callback Closure | boolean
Результат Cartalyst\Sentinel\Users\UserInteface | boolean
    public function register(array $credentials, $callback = null)
    {
        if ($callback !== null && !$callback instanceof Closure && !is_bool($callback)) {
            throw new InvalidArgumentException('You must provide a closure or a boolean.');
        }
        $this->fireEvent('sentinel.registering', $credentials);
        $valid = $this->users->validForCreation($credentials);
        if ($valid === false) {
            return false;
        }
        $argument = $callback instanceof Closure ? $callback : null;
        $user = $this->users->create($credentials, $argument);
        if ($callback === true) {
            $this->activate($user);
        }
        $this->fireEvent('sentinel.registered', $user);
        return $user;
    }

Usage Example

Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function register(array $data, $validate = true)
 {
     $this->rules = ['email' => 'required|unique:users', 'password' => 'required|confirmed', 'password_confirmation' => 'required'];
     if ($validate) {
         $this->validate($data);
     }
     if (!config('laraflock.dashboard.activations')) {
         $this->registerAndActivate($data, false);
         return true;
     }
     try {
         $user = $this->sentinel->register($data);
     } catch (QueryException $e) {
         throw new AuthenticationException(trans('dashboard::dashboard.errors.auth.create'));
     }
     if (!$user instanceof EloquentUser) {
         throw new AuthenticationException(trans('dashboard::dashboard.errors.auth.create'));
     }
     if (!isset($data['role'])) {
         $data['role'] = config('laraflock.dashboard.defaultRole');
     }
     if (!($role = $this->sentinel->findRoleBySlug($data['role']))) {
         throw new RolesException(trans('dashboard::dashboard.errors.role.found'));
     }
     $role->users()->attach($user);
     if (!($activation = $this->illuminateActivationRepository->create($user))) {
         throw new AuthenticationException(trans('dashboard::dashboard.errors.auth.activation.create'));
     }
     return $activation;
 }
All Usage Examples Of Cartalyst\Sentinel\Sentinel::register