public static function createFirstAdmin(array &$data)
    {
        if (empty($data['username'])) {
            $data['username'] = $data['email'];
        }

        $validationRules = [
            'name'       => 'required|max:255',
            'first_name' => 'required|max:255',
            'last_name'  => 'required|max:255',
            'email'      => 'required|email|max:255|unique:user',
            'password'   => 'required|confirmed|min:6',
            'username'   => 'min:6|unique:user,username|regex:/^\S*$/u|required'
        ];

        $validator = Validator::make($data, $validationRules);

        if ($validator->fails()) {
            $errors = $validator->getMessageBag()->all();
            $data = array_merge($data, ['errors' => $errors, 'version' => \Config::get('app.version')]);

            return false;
        } else {
            /** @type User $user */
            $attributes = array_only($data, ['name', 'first_name', 'last_name', 'email', 'username']);
            $attributes['is_active'] = 1;
            $user = static::create($attributes);

            $user->password = array_get($data, 'password');
            $user->is_sys_admin = 1;
            $user->save();

            // Register user
            RegisterContact::registerUser($user);
            // Reset admin_exists flag in cache.
            \Cache::forever('admin_exists', true);

            return $user;
        }
    }
public static function createFirstAdmin(array &$data)
    {
        if (empty($data['username'])) {
            $data['username'] = $data['email'];
        }

        $validationRules = [
            'name'       => 'required|max:255',
            'first_name' => 'required|max:255',
            'last_name'  => 'required|max:255',
            'email'      => 'required|email|max:255|unique:user',
            'password'   => 'required|confirmed|min:6',
            'username'   => 'min:6|unique:user,username|regex:/^\S*$/u|required'
        ];

        $validator = Validator::make($data, $validationRules);

        if ($validator->fails()) {
            $errors = $validator->getMessageBag()->all();
            $data = array_merge($data, ['errors' => $errors, 'version' => \Config::get('app.version')]);

            return false;
        } else {
            /** @type User $user */
            $attributes = array_only($data, ['name', 'first_name', 'last_name', 'email', 'username']);
            $attributes['is_active'] = 1;
            $user = static::create($attributes);

            $user->password = array_get($data, 'password');
            $user->is_sys_admin = 1;
            $user->save();

            // Register user
            RegisterContact::registerUser($user);
            // Reset admin_exists flag in cache.
            \Cache::forever('admin_exists', true);

            return $user;
        }
    }
public static function createFirstAdmin ( array & $ data ) { if ( empty ( $ data [ 'username' ] ) ) { $ data [ 'username' ] = $ data [ 'email' ] ; } $ validationRules = [ 'name' => 'required|max:255' , 'first_name' => 'required|max:255' , 'last_name' => 'required|max:255' , 'email' => 'required|email|max:255|unique:user' , 'password' => 'required|confirmed|min:6' , 'username' => 'min:6|unique:user,username|regex:/^\S*$/u|required' ] ; $ validator = Validator :: make ( $ data , $ validationRules ) ; if ( $ validator -> fails ( ) ) { $ errors = $ validator -> getMessageBag ( ) -> all ( ) ; $ data = array_merge ( $ data , [ 'errors' => $ errors , 'version' => \ Config :: get ( 'app.version' ) ] ) ; return false ; } else { /** @type User $user */ $ attributes = array_only ( $ data , [ 'name' , 'first_name' , 'last_name' , 'email' , 'username' ] ) ; $ attributes [ 'is_active' ] = 1 ; $ user = static :: create ( $ attributes ) ; $ user -> password = array_get ( $ data , 'password' ) ; $ user -> is_sys_admin = 1 ; $ user -> save ( ) ; // Register user RegisterContact :: registerUser ( $ user ) ; // Reset admin_exists flag in cache. \ Cache :: forever ( 'admin_exists' , true ) ; return $ user ; } }
Creates first admin user.

@param  array $data

@return User|boolean
Creates first admin user .