encryptable icon indicating copy to clipboard operation
encryptable copied to clipboard

Invalid payload

Open synkyo opened this issue 8 years ago • 6 comments

"Invalid payload" error thrown when using a new model with encryptable attributes is used.

e.g. $book = new Book(); return view('book.store', ['book' => $book]);

synkyo avatar Jul 10 '17 14:07 synkyo

Do you have a stack trace that relates this error to this package? I tried a fresh laravel install:

// Book.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Sagalbot\Encryptable\Encryptable;

class Book extends Model
{
    use Encryptable;

    protected $encryptable = ['name'];

    protected $fillable = ['name'];
}
//  routes/web.php

Route::get('/', function () {
    $book = new \App\Book();
    return view('welcome', ['book' => $book]);
});
<!-- welcome.blade.php -->

<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <title>Laravel</title>
    </head>
    <body>
        {{ dd($book) }}
    </body>
</html>

No errors.

sagalbot avatar Jul 10 '17 15:07 sagalbot

Seems the issue was that when the value is empty, it is still passed to decrypt function thus creating a payload error. I have created a pull request which resolves the issue.

Pull Request: Fixed payload error when model property is empty #2

synkyo avatar Aug 08 '17 13:08 synkyo

Implemented your pull request, still throws the same error, did you have more luck?

mikkellindblom avatar Aug 08 '17 16:08 mikkellindblom

Thanks for the input. I can recreate this in the browser, but I can't seem to duplicate it in a regression test, which leads me to believe there is something additional happening in the view layer. I'll dig deeper.

sagalbot avatar Aug 08 '17 22:08 sagalbot

Did you guys ever solve this issue?

Just to recap otherwise; As long as I make sure that all encrypted fields have a value everything is fine?

crashkonijn avatar Nov 10 '17 18:11 crashkonijn

I had the same issue. The solution of @synkyo works for me in our current project.

bosix avatar Aug 21 '18 05:08 bosix