diff --git a/resources/views/components/youtube.blade.php b/resources/views/components/youtube.blade.php
index b8564a9..4d6795c 100644
--- a/resources/views/components/youtube.blade.php
+++ b/resources/views/components/youtube.blade.php
@@ -1,5 +1,5 @@
@php
- $ytData = new \BenBjurstrom\Prezet\Data\YoutubeData($attributes->all());
+ $ytData = new \BenBjurstrom\Prezet\Data\YoutubeData($attributes->getAttributes());
@endphp
diff --git a/routes/prezet.php b/routes/prezet.php
index cdd637a..e7b2701 100644
--- a/routes/prezet.php
+++ b/routes/prezet.php
@@ -4,7 +4,7 @@
use BenBjurstrom\Prezet\Http\Controllers\IndexController;
use BenBjurstrom\Prezet\Http\Controllers\OgimageController;
use BenBjurstrom\Prezet\Http\Controllers\ShowController;
-use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
+use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Support\Facades\Route;
use Illuminate\View\Middleware\ShareErrorsFromSession;
@@ -12,7 +12,7 @@
Route::withoutMiddleware([
ShareErrorsFromSession::class,
StartSession::class,
- ValidateCsrfToken::class,
+ VerifyCsrfToken::class,
])
->group(function () {
Route::get('prezet/img/{path}', ImageController::class)
diff --git a/src/Actions/UpdateIndex.php b/src/Actions/UpdateIndex.php
index 5933091..2aabb9d 100644
--- a/src/Actions/UpdateIndex.php
+++ b/src/Actions/UpdateIndex.php
@@ -22,7 +22,7 @@ public static function handle(): void
'slug' => $doc->slug,
'category' => $doc->category,
'draft' => $doc->draft,
- 'frontmatter' => $doc->toJson(),
+ 'frontmatter' => $doc,
'created_at' => $doc->createdAt,
'updated_at' => $doc->updatedAt,
]);
diff --git a/src/Models/Document.php b/src/Models/Document.php
index 7e73f14..3139ca0 100644
--- a/src/Models/Document.php
+++ b/src/Models/Document.php
@@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+use TypeError;
/**
* @property string $slug
@@ -37,10 +38,26 @@ protected function casts(): array
{
return [
'draft' => 'boolean',
- 'frontmatter' => FrontmatterData::class,
];
}
+ /**
+ * @return Attribute
+ */
+ protected function frontmatter(): Attribute
+ {
+ return Attribute::make(
+ get: function (mixed $value) {
+ if (! is_string($value)) {
+ throw new TypeError('Frontmatter passed to Attribute::make must be a string');
+ }
+
+ return FrontmatterData::fromJson($value);
+ },
+ set: fn (FrontmatterData $value) => $value->toJson()
+ );
+ }
+
/**
* @return BelongsToMany
*/