mirror of
https://github.com/archtechx/laravel-tips.git
synced 2025-12-12 05:14:04 +00:00
improve thread links
This commit is contained in:
parent
57ab16675e
commit
4f2b5dc999
4 changed files with 19 additions and 6 deletions
|
|
@ -2,13 +2,21 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Twitter\Tweet;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Orbit\Concerns\Orbital;
|
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
|
class Thread extends Model
|
||||||
{
|
{
|
||||||
use Orbital;
|
use Orbital;
|
||||||
|
|
@ -59,4 +67,9 @@ class Thread extends Model
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function links(): Collection
|
||||||
|
{
|
||||||
|
return collect($this->links)->map(fn (array $link, string $key) => route('thread.link', ['thread' => $this, 'link' => $key]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,9 @@
|
||||||
<dt class="text-sm text-gray-500">Links</dt>
|
<dt class="text-sm text-gray-500">Links</dt>
|
||||||
|
|
||||||
<dd>
|
<dd>
|
||||||
@foreach($links as $link)
|
@foreach($links as $text => $url)
|
||||||
<x-link href="{{ $link['url'] }}" target="_blank">
|
<x-link href="{{ $url }}" target="_blank">
|
||||||
{{ ucfirst($link['name']) }}
|
{{ ucfirst($text) }}
|
||||||
</x-link>
|
</x-link>
|
||||||
@endforeach
|
@endforeach
|
||||||
</dd>
|
</dd>
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
<section class="py-12 bg-white md:py-24">
|
<section class="py-12 bg-white md:py-24">
|
||||||
<x:container>
|
<x:container>
|
||||||
<x:author-card :tip="$thread" :links="$thread->links" />
|
<x:author-card :tip="$thread" :links="$thread->links()" />
|
||||||
</x:container>
|
</x:container>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ Route::middleware('static')->group(function () {
|
||||||
|
|
||||||
Route::get('/threads/{thread}/{link}', function (Thread $thread, string $link) {
|
Route::get('/threads/{thread}/{link}', function (Thread $thread, string $link) {
|
||||||
return redirect($thread->links[$link]['url']);
|
return redirect($thread->links[$link]['url']);
|
||||||
})->name('thread.show');
|
})->name('thread.link');
|
||||||
|
|
||||||
Route::get('/threads/{thread}', function (Thread $thread) {
|
Route::get('/threads/{thread}', function (Thread $thread) {
|
||||||
return view('threads.show', [
|
return view('threads.show', [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue