encryptable
encryptable copied to clipboard
Invalid payload
"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]);
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.
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
Implemented your pull request, still throws the same error, did you have more luck?
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.
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?
I had the same issue. The solution of @synkyo works for me in our current project.