Skip to content

Commit

Permalink
71 Laravel 10 compatibility (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjurstrom authored Sep 19, 2024
1 parent 0221d20 commit 5e3f0c7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion resources/views/components/youtube.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@php
$ytData = new \BenBjurstrom\Prezet\Data\YoutubeData($attributes->all());
$ytData = new \BenBjurstrom\Prezet\Data\YoutubeData($attributes->getAttributes());
@endphp

<div class="aspect-video" {{ $attributes }}>
Expand Down
4 changes: 2 additions & 2 deletions routes/prezet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
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;

Route::withoutMiddleware([
ShareErrorsFromSession::class,
StartSession::class,
ValidateCsrfToken::class,
VerifyCsrfToken::class,
])
->group(function () {
Route::get('prezet/img/{path}', ImageController::class)
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/UpdateIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand Down
19 changes: 18 additions & 1 deletion src/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,10 +38,26 @@ protected function casts(): array
{
return [
'draft' => 'boolean',
'frontmatter' => FrontmatterData::class,
];
}

/**
* @return Attribute<string, never>
*/
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<Tag>
*/
Expand Down

0 comments on commit 5e3f0c7

Please sign in to comment.