src/Utility/TokenTrait.php
public function create($token, array $options = [])
    {
        $entity = new Token(compact('token'));

        foreach (['user_id', 'type', 'extra', 'expiry'] as $key) {
            if (array_key_exists($key, $options)) {
                $entity->set($key, $options[$key]);
            }
        }

        if (!$this->getTable()->save($entity)) {
            $field = collection(array_keys($entity->getErrors()))->first();
            $error = collection(collection(($entity->getErrors()))->first())->first();

            throw new LogicException(sprintf('Error for `%s` field: %s', $field, lcfirst($error)));
        }

        return $entity->token;
    }
public function create($token, array $options = [])
    {
        $entity = new Token(compact('token'));

        foreach (['user_id', 'type', 'extra', 'expiry'] as $key) {
            if (array_key_exists($key, $options)) {
                $entity->set($key, $options[$key]);
            }
        }

        if (!$this->getTable()->save($entity)) {
            $field = collection(array_keys($entity->getErrors()))->first();
            $error = collection(collection(($entity->getErrors()))->first())->first();

            throw new LogicException(sprintf('Error for `%s` field: %s', $field, lcfirst($error)));
        }

        return $entity->token;
    }
public function create ( $ token , array $ options = [ ] ) { $ entity = new Token ( compact ( 'token' ) ) ; foreach ( [ 'user_id' , 'type' , 'extra' , 'expiry' ] as $ key ) { if ( array_key_exists ( $ key , $ options ) ) { $ entity -> set ( $ key , $ options [ $ key ] ) ; } } if ( ! $ this -> getTable ( ) -> save ( $ entity ) ) { $ field = collection ( array_keys ( $ entity -> getErrors ( ) ) ) -> first ( ) ; $ error = collection ( collection ( ( $ entity -> getErrors ( ) ) ) -> first ( ) ) -> first ( ) ; throw new LogicException ( sprintf ( 'Error for `%s` field: %s' , $ field , lcfirst ( $ error ) ) ) ; } return $ entity -> token ; }
Creates a token.

Valid optios values: `user_id`, `type`, `extra`, `expiry`.
@param string $token Token value
@param array $options Options
@return string Token value
@throws LogicException
@uses getTable()
Creates a token .