Skip to content
This repository was archived by the owner on Apr 7, 2021. It is now read-only.
This repository was archived by the owner on Apr 7, 2021. It is now read-only.

Type error: substr() expects parameter 2 to be integer, boolean given #19

Closed
@WouterFlorijn

Description

@WouterFlorijn

When using the decryptedAttribute function on an encrypted value, I get the following error:

Symfony\Component\Debug\Exception\FatalThrowableError : Type error: substr() expects parameter 2 to be integer, boolean given

at C:\wamp\www\lifestream\vendor\austinheap\laravel-database-encryption\src\Traits\HasEncryptedAttributes.php: 171

I am encrypting/decrypting data from a migration to ensure that existing data will still work.

My migration looks like this:

class EncryptData extends Migration
{
    public function up()
    {
        $this->encryptModels(SomeModel::all());
    }

    public function down()
    {
        $this->decryptModels(SomeModel::all());
    }

    private function encryptModels($models)
    {
        foreach ($models as $model)
        {
            if (!property_exists($model, 'encrypted'))
                return;
            foreach ($model->encrypted as $key)
            {
                $value = $model->getAttributeRaw($key);
                $value = $model->encryptedAttribute($value);
                $model->setAttributeRaw($key, $value);
                $model->save();
            }
        }
    }

    private function decryptModels($models)
    {
        foreach ($models as $model)
        {
            if (!property_exists($model, 'encrypted'))
                return;
            foreach ($model->encrypted as $key)
            {
                $value = $model->getAttributeRaw($key);
                $value = $model->decryptedAttribute($value);
                $model->setAttributeRaw($key, $value);
                $model->save();
            }
        }
    }
}

The encryption part works fine, but rolling back the migration throws the exception. Also, the encrypted values look like this:

��__LARAVEL-DATABASE-ENCRYPTED-VERSION-00-01-00__��version�VERSION-00-01-00��type�string[native]��eyJpdiI6IjJEYTJuRkdMeTFTQ1pCNXRCanNvUUE9PSIsInZhbHVlIjoiYlo0d2NIOFwvd1BtNER6OUZIOUpIWGc9PSIsIm1hYyI6IjQ5Mzk2OTNlNTAyZGI1NmJkMmUyZjQyNDZlZWYwYTMzYjM3MzRhOTU2NzAzMDc0OGI1Y2Y4ZjczZTk2ZDdhNjQifQ==

Are the �� characters supposed to look like this?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions