From 4f2b5dc9992bdef89a9ce9a5f754081116b0af70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 9 Apr 2021 18:53:27 +0200 Subject: [PATCH] improve thread links --- app/Models/Thread.php | 15 ++++++++++++++- resources/views/components/author-card.blade.php | 6 +++--- resources/views/threads/show.blade.php | 2 +- routes/web.php | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/Models/Thread.php b/app/Models/Thread.php index a54a43e..f077cbc 100644 --- a/app/Models/Thread.php +++ b/app/Models/Thread.php @@ -2,13 +2,21 @@ namespace App\Models; -use App\Twitter\Tweet; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Collection; use Orbit\Concerns\Orbital; +/** + * @property string $slug + * @property string $title + * @property string|null $tweet_id + * @property string $author_username + * @property string $content + * @property array $links + */ class Thread extends Model { use Orbital; @@ -59,4 +67,9 @@ class Thread extends Model { return false; } + + public function links(): Collection + { + return collect($this->links)->map(fn (array $link, string $key) => route('thread.link', ['thread' => $this, 'link' => $key])); + } } diff --git a/resources/views/components/author-card.blade.php b/resources/views/components/author-card.blade.php index f3a3d41..9dcdf73 100644 --- a/resources/views/components/author-card.blade.php +++ b/resources/views/components/author-card.blade.php @@ -42,9 +42,9 @@
Links
- @foreach($links as $link) - - {{ ucfirst($link['name']) }} + @foreach($links as $text => $url) + + {{ ucfirst($text) }} @endforeach
diff --git a/resources/views/threads/show.blade.php b/resources/views/threads/show.blade.php index cf95d06..a259125 100644 --- a/resources/views/threads/show.blade.php +++ b/resources/views/threads/show.blade.php @@ -24,7 +24,7 @@
- +
diff --git a/routes/web.php b/routes/web.php index 71fd473..501cf81 100644 --- a/routes/web.php +++ b/routes/web.php @@ -22,7 +22,7 @@ Route::middleware('static')->group(function () { Route::get('/threads/{thread}/{link}', function (Thread $thread, string $link) { return redirect($thread->links[$link]['url']); - })->name('thread.show'); + })->name('thread.link'); Route::get('/threads/{thread}', function (Thread $thread) { return view('threads.show', [