whitecube / nova-page

Static pages content management for Laravel Nova
https://whitecube.github.io/nova-page
MIT License
238 stars 41 forks source link

json_decode() expects parameter 1 to be string, array given #69

Closed rabichawila closed 3 years ago

rabichawila commented 3 years ago

i have a template like this:

namespace App\Nova\Templates;

use Whitecube\NovaPage\Pages\Template;

class Home extends Template
{
    /**
     * The JSON attributes that should be automatically decoded
     *
     * @var array
     */
    protected $jsonAttributes = ['title', 'body'];
}

But when i call it i get

json_decode() expects parameter 1 to be string, array given

 Error occured here
 //vendor/whitecube/nova-page/src/Sources/Database.php
      $model = $this->getOriginal($template);

        if(!$model->id) {
            return;
        }

        // dd($model->attributes);

        $attributes = $this->getParsedAttributes(
            $template,
            $model->attributes ? json_decode($model->attributes, true) : []
        );

        return [
            'title' => $model->title,
            'created_at' => $model->created_at,
            'updated_at' => $model->updated_at,
            'attributes' => $attributes
        ];
rabichawila commented 3 years ago

Silenced the error with: ` // in App\Models\StaticPage

protected $casts = [
    'attributes' => "string"
];

`