-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not working on json casting to array #14
Comments
I know it might be too late but... |
I am also having this issue with a casted array on Laravel 8. When I take the encrypted string out of the database and pass it through Crypt::decrypt() the result is a PHP array. It looks like when the field is being stored the array is encrypted BEFORE it is passed through json_encode (or not passed through json_encode at all) (Laravel 8 on PHP 7.4) |
To fix this, you just need to add the following just above line 67 (at time of writing) of the Trait so that the PHP array is cast to JSON before storing. Tested successfully.
|
merged? or anything? |
Schema::create('customers', function (Blueprint $table) { $table->id(); $table->json('data'); $table->timestamps(); });
` protected $casts = [
'data' => 'array',
];
Customer::firstOrCreate(['data' => ['name' => 'me', 'email' => '[email protected]'] ]);
App\Customer {#3958 data: ""eyJpdiI6Iko3aG5OdmhEb1k0TFcyK0ZDSUFRL3c9PSIsInZhbHVlIjoiSzZlaEJEeUlMTEc5OEVveUN6SXJseUJ0OTV3dWNiNTBpa3Vxd1pwTzlQYW9FbUpXdGtWZkZmWmN6YzI4b1pVeC9lRE9BN2V5MTBpSUhyVUw5YkRMOHc9PSIsIm1hYyI6ImM1ZGQzMDNkYjJhNzUyNTNkZGQzODlkYWY3YTYzYTg4ODYwMGYwN2E4NWY2MTcyNWI0YWZlNzRkN2M3ODlmM2EifQ=="", updated_at: "2020-05-23 17:21:38", created_at: "2020-05-23 17:21:38", id: 1, }
Customer::first()->data['email']
PHP Warning: json_decode() expects parameter 1 to be string, array given in /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php on line 820
PHP Notice: Trying to access array offset on value of type null in Psy Shell code on line 1
The text was updated successfully, but these errors were encountered: