File tree Expand file tree Collapse file tree 4 files changed +34
-5
lines changed Expand file tree Collapse file tree 4 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ public function mount(): void
3030 public function render (): View
3131 {
3232 $ articles = Article::published ();
33+ $ tags = Tag::whereHas ('articles ' , function ($ query ) {
34+ $ query ->published ();
35+ })->orderBy ('name ' )->get ();
3336
3437 if ($ this ->tag ) {
3538 $ articles ->forTag ($ this ->tag );
@@ -39,6 +42,7 @@ public function render(): View
3942
4043 return view ('livewire.show-articles ' , [
4144 'articles ' => $ articles ->paginate (10 ),
45+ 'tags ' => $ tags ,
4246 'selectedTag ' => $ this ->tag ,
4347 'selectedSortBy ' => $ this ->sortBy ,
4448 ]);
Original file line number Diff line number Diff line change 2727 <div class =" flex items-center justify-between mt-6" >
2828 <div class =" flex items-center" >
2929 <div class =" flex-shrink-0" >
30- <a href =" # " >
30+ <a href =" {{ route ( ' profile ' , $article -> author () -> username ()) } } " >
3131 <img class =" h-10 w-10 rounded-full" src =" {{ $article -> author ()-> gravatarUrl ($avatarSize ?? 250 ) } }" alt =" {{ $article -> author ()-> name } }" />
3232 </a >
3333 </div >
3434 <div class =" ml-3" >
3535 <p class =" text-sm leading-5 font-medium text-gray-900" >
36- <a href =" # " >
36+ <a href =" {{ route ( ' profile ' , $article -> author () -> username ()) } } " >
3737 {{ $article -> author ()-> name () } }
3838 </a >
3939 </p >
7575 </button >
7676 </span >
7777
78+ <a
79+ href =" {{ route (' articles.create' ) } }"
80+ class =" button button-primary button-full mb-4"
81+ >
82+ Create Article
83+ </a >
84+
7885 <ul class =" tags" >
7986 <li class =" {{ ! $selectedTag ? ' active' : ' ' } }" >
8087 <button wire:click =" toggleTag('')" >
8188 All
8289 </button >
8390 </li >
8491
85- @foreach (App \ Models \Tag :: whereHas ( ' articles ' ) -> orderBy ( ' name ' ) -> get () as $tag )
92+ @foreach ($tags as $tag )
8693 <li class =" {{ $selectedTag === $tag -> slug () ? ' active' : ' ' } }" >
8794 <button wire:click =" toggleTag('{{ $tag -> slug () } } ')" >
8895 {{ $tag -> name () } }
Original file line number Diff line number Diff line change 2323@section (' content' )
2424 <div class =" container mx-auto px-4 py-8 flex flex-wrap flex-col-reverse lg:flex-row" >
2525 <div class =" w-full md:w-3/4 md:pr-3" >
26- @foreach ($articles as $article )
26+ @forelse ($articles as $article )
2727 <div class =" pb-8 mb-8 border-b-2" >
2828 <div >
2929 @if ($article -> isNotPublished () )
102102 </div >
103103 </div >
104104 </div >
105- @endforeach
105+ @empty
106+ <p class =" text-gray-600 text-base" >
107+ You haven't created any articles yet
108+ </p >
109+ @endforelse
106110
107111 {{ $articles -> links () } }
108112 </div >
Original file line number Diff line number Diff line change @@ -618,4 +618,18 @@ public function users_get_a_mail_notification_when_their_article_is_approved()
618618
619619 Notification::assertSentTo ($ user , ArticleApprovedNotification::class);
620620 }
621+
622+ /** @test */
623+ public function tags_are_not_rendered_for_unpublished_articles ()
624+ {
625+ $ tag = factory (Tag::class)->create (['name ' => 'Test Tag ' ]);
626+ $ article = factory (Article::class)->create ([
627+ 'slug ' => 'my-first-article ' ,
628+ 'submitted_at ' => now ()
629+ ]);
630+ $ article ->syncTags ([$ tag ->id ]);
631+
632+ $ this ->get ('/articles ' )
633+ ->dontSee ('Test Tag ' );
634+ }
621635}
You can’t perform that action at this time.
0 commit comments