Skip to content

Commit

Permalink
feat: add dynamic default preview image
Browse files Browse the repository at this point in the history
  • Loading branch information
yilanboy committed Dec 21, 2024
1 parent 5d1f2c4 commit 5177120
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
19 changes: 19 additions & 0 deletions app/Http/Controllers/PreviewController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Controllers;

use App\Models\Post;
use Yilanboy\Preview\Image\Builder;

class PreviewController extends Controller
{
public function __invoke(Post $post): void
{
new Builder()
->size(width: 1200, height: 600)
->backgroundColor('#14b8a6')
->header(text: config('app.name'), color: 'white')
->title(text: $post->title, color: 'white', fontSize: 60)
->output();
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"laravel/tinker": "^2.7",
"league/flysystem-aws-s3-v3": "^3.0",
"livewire/livewire": "^3.0",
"spatie/laravel-feed": "^4.1"
"spatie/laravel-feed": "^4.1",
"yilanboy/preview": "^1.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.6",
Expand Down
50 changes: 49 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions resources/views/livewire/pages/posts/show-post-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

@if (!empty($post->preview_url))
@section('preview_url', $post->preview_url)
@else
@section('preview_url', route('posts.preview', $post->id))
@endif

@assets
Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\PreviewController;
use App\Http\Controllers\User\DestroyUserController;
use App\Livewire\Pages\Categories\ShowCategoryPage;
use App\Livewire\Pages\Notifications\NotificationIndexPage;
Expand Down Expand Up @@ -49,6 +50,8 @@
Route::prefix('/posts')->group(function () {
Route::get('/', PostIndexPage::class)->name('posts.index');

Route::get('/{post}/preview', PreviewController::class)->name('posts.preview');

Route::middleware(['auth', 'verified'])->group(function () {
Route::get('/create', CreatePostPage::class)->name('posts.create');
Route::get('/{id}/edit', EditPostPage::class)->name('posts.edit');
Expand Down

0 comments on commit 5177120

Please sign in to comment.