Skip to content

Commit 4f45d74

Browse files
authored
- Author name show in post-index and post-show page (#2)
- Post publish date formatted - Calendar icon added before post publish date - Author image added before Author name
1 parent b650457 commit 4f45d74

File tree

4 files changed

+77
-7
lines changed

4 files changed

+77
-7
lines changed

stubs/modules/Blog/Http/Controllers/SitePostController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SitePostController extends SiteController
1313
{
1414
public function index(GetArchiveOptions $getArchiveOptions, GetTagOptions $getTagOptions): View
1515
{
16-
$posts = Post::with('tags')
16+
$posts = Post::with('tags', 'author')
1717
->where('published_at', '<=', Carbon::now())
1818
->latest()
1919
->paginate(6);
@@ -26,7 +26,7 @@ public function index(GetArchiveOptions $getArchiveOptions, GetTagOptions $getTa
2626

2727
public function show($slug)
2828
{
29-
$post = Post::where('slug', $slug)->first();
29+
$post = Post::with('author')->where('slug', $slug)->first();
3030

3131
return view('blog::post-show', compact('post'));
3232
}

stubs/modules/Blog/Models/Post.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ protected static function newFactory(): Factory
6363
{
6464
return BlogPostFactory::new();
6565
}
66+
67+
public function author()
68+
{
69+
return $this->belongsTo(Author::class, 'blog_author_id');
70+
}
6671
}

stubs/modules/Blog/views/post-index.blade.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,36 @@ class="aspect-[16/9] w-full rounded-2xl sm:aspect-[2/1] lg:aspect-[3/2] flex it
4949
</a>
5050
</div>
5151
<div class="max-w-xl">
52-
<div class="mt-8 flex items-center gap-x-4 text-xs">
53-
<time datetime="{{ $post->published_at }}" class="text-gray-500">
54-
Published at: {{ $post->published_at->format('d/m/Y') }}
55-
</time>
52+
<div class="mt-8 flex items-center gap-2 text-xs">
53+
<div class="text-gray-600 italic flex items-center gap-1">
54+
55+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"
56+
class="h-3 w-3">
57+
<path
58+
d="M17 3H21C21.5523 3 22 3.44772 22 4V20C22 20.5523 21.5523 21 21 21H3C2.44772 21 2 20.5523 2 20V4C2 3.44772 2.44772 3 3 3H7V1H9V3H15V1H17V3ZM4 9V19H20V9H4ZM6 11H8V13H6V11ZM11 11H13V13H11V11ZM16 11H18V13H16V11Z">
59+
</path>
60+
</svg>
61+
{{ $post->published_at->format('F d, Y') }}
62+
</div>
63+
64+
<div class="text-gray-600 italic flex items-center gap-1">
65+
@if ($post->author)
66+
@if ($post->author->image_url)
67+
<img src="{{ $post->author->image_url }}" alt="{{ $post->author->name }}"
68+
class="h-4 w-4 rounded-md bg-gray-100 object-cover">
69+
@else
70+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
71+
fill="currentColor" class="h-4 w-4">
72+
<path
73+
d="M4 22C4 17.5817 7.58172 14 12 14C16.4183 14 20 17.5817 20 22H4ZM12 13C8.685 13 6 10.315 6 7C6 3.685 8.685 1 12 1C15.315 1 18 3.685 18 7C18 10.315 15.315 13 12 13Z">
74+
</path>
75+
</svg>
76+
@endif
77+
{{ $post->author->name }}
78+
@endif
79+
</div>
5680
</div>
81+
5782
<div class="group relative mb-2">
5883
<h3
5984
class="mt-3 text-lg font-semibold leading-6 text-gray-900 group-hover:text-gray-600 min-h-12 ">

stubs/modules/Blog/views/post-show.blade.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,47 @@
1010
{{ $post->title }}
1111
</h2>
1212

13-
<p class="text-gray-500 mb-4">Published at: {{ $post->published_at->format('d/m/Y') }}</p>
13+
14+
<div class="flex items-center gap-2 mb-4 text-sm">
15+
<div class="text-gray-600 italic flex items-center gap-1">
16+
17+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="h-4 w-4">
18+
<path
19+
d="M17 3H21C21.5523 3 22 3.44772 22 4V20C22 20.5523 21.5523 21 21 21H3C2.44772 21 2 20.5523 2 20V4C2 3.44772 2.44772 3 3 3H7V1H9V3H15V1H17V3ZM4 9V19H20V9H4ZM6 11H8V13H6V11ZM11 11H13V13H11V11ZM16 11H18V13H16V11Z">
20+
</path>
21+
</svg>
22+
{{ $post->published_at->format('F d, Y') }}
23+
</div>
24+
25+
<div class="text-gray-600 italic flex items-center gap-1">
26+
@if ($post->author)
27+
@if ($post->author->image_url)
28+
<img src="{{ $post->author->image_url }}" alt="{{ $post->author->name }}"
29+
class="h-4 w-4 rounded-md bg-gray-100 object-cover">
30+
@else
31+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"
32+
class="h-4 w-4">
33+
<path
34+
d="M4 22C4 17.5817 7.58172 14 12 14C16.4183 14 20 17.5817 20 22H4ZM12 13C8.685 13 6 10.315 6 7C6 3.685 8.685 1 12 1C15.315 1 18 3.685 18 7C18 10.315 15.315 13 12 13Z">
35+
</path>
36+
</svg>
37+
@endif
38+
{{ $post->author->name }}
39+
@endif
40+
</div>
41+
</div>
42+
43+
44+
<div class="relative w-full mb-4">
45+
<a href="/blog/{{ $post->slug }}" class="block">
46+
@if ($post->image_url)
47+
<img src="{{ $post->image_url }}" alt="{{ $post->title }}"
48+
class="aspect-[16/9] w-full rounded-2xl bg-gray-100 object-cover sm:aspect-[2/1] lg:aspect-[3/2]">
49+
@endif
50+
<div class="absolute inset-0 rounded-2xl ring-1 ring-inset ring-gray-900/10"></div>
51+
</a>
52+
</div>
53+
1454

1555
<div>
1656
{!! $post->content !!}

0 commit comments

Comments
 (0)