Php Laravel Sentry注册用户,即使组无效

Php Laravel Sentry注册用户,即使组无效,php,laravel,cartalyst-sentry,Php,Laravel,Cartalyst Sentry,问题是,即使指定的组不存在,Sentry仍在注册用户 if(Request::isMethod('post')) { $validation = Validator::make([ 'username' => Input::get('username'), 'password' => Input::get('password'), 'password_confirmation' => I

问题是,即使指定的组不存在,Sentry仍在注册用户

if(Request::isMethod('post'))
{

    $validation = Validator::make([
            'username'  =>  Input::get('username'),
            'password'  =>  Input::get('password'),
            'password_confirmation' =>  Input::get('password_confirmation')
        ],
        [
            'username'  =>  'unique:users,username|required',
            'password'  =>  'same:password_confirmation|required'
        ]);

    if($validation->fails())
        return Redirect::route('addUser')
            ->withErrors($validation->getMessageBag())
            ->withInput(Input::except(['password', 'password_confirmation']));
    else
    {
        /** Do sentry stuff */
        try
        {
            $activated = Input::get('activated') ? true : false;

            // Create the user
            $user = Sentry::createUser(array(
                'username'  =>  Input::get('username'),
                'email'     => Input::get('email'),
                'password'  => Input::get('password'),
                'activated' => $activated,
            ));

            $group = Sentry::findGroupById(Input::get('group'));
            $user->addGroup($group);
        }
        catch (Cartalyst\Sentry\Users\LoginRequiredException $e)
        {
            $message[] = 'Login field is required.';
        }
        catch (Cartalyst\Sentry\Users\PasswordRequiredException $e)
        {
            $message[] = 'Password field is required.';
        }
        catch (Cartalyst\Sentry\Users\UserExistsException $e)
        {
            $message[] = 'User with this login already exists.';
        }
        catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e)
        {
            $message[] = 'Group was not found.';
        }



        if(isset($message))
            return Redirect::route('addUser')
                ->withErrors($message)
                ->withInput(Input::except(['password', 'password_confirmation']));
        else
        {
            $message = 'User has been added';
            return Redirect::route('addUser')
                ->with('success', $message);
        }
    }
}
return $this->render('admin/users/add');
现在,当抛出异常时,我假设不会创建用户,但是我不明白为什么会这样


如果没有引发异常,是否有一种特定的方法或另一种方法我缺少,仅注册用户?

用户必须存在并且具有Sentry的id才能尝试添加组。我的建议是将它分成两个try/catch块:一个用于添加用户,另一个用于将用户添加到组,然后

    catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e)
    {
        $message[] = 'Group was not found.';
        $user->delete();
    }