Skip to content

Commit e22474e

Browse files
committed
Use POST requests for thread subscribing
1 parent f1c2328 commit e22474e

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1+
@props([
2+
'action' => null,
3+
])
4+
5+
16
<span class="inline-flex rounded shadow {{ $attributes->get('class') }}">
27
@if ($attributes->has('href'))
38
<a {{ $attributes->except('class') }} class="w-full bg-white border border-gray-200 rounded py-2 px-4 inline-flex justify-center text-lg leading-6 text-gray-900 hover:bg-gray-100">
49
{{ $slot }}
510
</a>
11+
@elseif ($action)
12+
<form method="POST" action="{{ $action }}" class="w-full">
13+
@csrf
14+
@method('POST')
15+
16+
<button type="submit" {{ $attributes->except('class') }} class="w-full bg-white border border-gray-200 rounded py-2 px-4 inline-flex justify-center text-lg leading-6 text-gray-900 hover:bg-gray-100">
17+
{{ $slot }}
18+
</button>
19+
</form>
620
@else
721
<button {{ $attributes->except('class') }} class="w-full bg-white border border-gray-200 rounded py-2 px-4 inline-flex justify-center text-lg leading-6 text-gray-900 hover:bg-gray-100">
822
{{ $slot }}
923
</button>
1024
@endif
11-
</span>
25+
</span>

resources/views/components/threads/subscribe.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<h3 class="text-xl font-semibold">Notifications</h3>
66

77
@can(App\Policies\ThreadPolicy::UNSUBSCRIBE, $thread)
8-
<x-buttons.secondary-cta href="{{ route('threads.unsubscribe', $thread->slug()) }}" class="w-full mt-3">
8+
<x-buttons.secondary-cta action="{{ route('threads.unsubscribe', $thread->slug()) }}" class="w-full mt-3">
99
<span class="flex items-center justify-center gap-x-2">
1010
<x-heroicon-o-volume-off class="w-6 h-6" />
1111
Unsubscribe
@@ -16,7 +16,7 @@
1616
You are currently receiving notifications of updates from this thread.
1717
</p>
1818
@elsecan(App\Policies\ThreadPolicy::SUBSCRIBE, $thread)
19-
<x-buttons.secondary-cta href="{{ route('threads.subscribe', $thread->slug()) }}" class="w-full mt-3">
19+
<x-buttons.secondary-cta action="{{ route('threads.subscribe', $thread->slug()) }}" class="w-full mt-3">
2020
<span class="flex items-center justify-center gap-x-2">
2121
<x-heroicon-o-volume-up class="w-6 h-6" />
2222
Subscribe
@@ -28,4 +28,4 @@
2828
</p>
2929
@endcan
3030
</div>
31-
</div>
31+
</div>

routes/web.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
Route::delete('{thread}', [ThreadsController::class, 'delete'])->name('threads.delete');
8787
Route::put('{thread}/mark-solution/{reply}', [ThreadsController::class, 'markSolution'])->name('threads.solution.mark');
8888
Route::put('{thread}/unmark-solution', [ThreadsController::class, 'unmarkSolution'])->name('threads.solution.unmark');
89-
Route::get('{thread}/subscribe', [ThreadsController::class, 'subscribe'])->name('threads.subscribe');
90-
Route::get('{thread}/unsubscribe', [ThreadsController::class, 'unsubscribe'])->name('threads.unsubscribe');
89+
Route::post('{thread}/subscribe', [ThreadsController::class, 'subscribe'])->name('threads.subscribe');
90+
Route::post('{thread}/unsubscribe', [ThreadsController::class, 'unsubscribe'])->name('threads.unsubscribe');
9191

9292
Route::get('tags/{tag}', [TagsController::class, 'show'])->name('forum.tag');
9393
});

tests/Feature/SubscriptionsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
$this->login();
7575

7676
$this->visit("/forum/$slug")
77-
->click('Subscribe')
77+
->press('Subscribe')
7878
->seePageIs("/forum/$slug")
7979
->see("You're now subscribed to this thread.");
8080
});
@@ -87,7 +87,7 @@
8787
$this->loginAs($user);
8888

8989
$this->visit("/forum/$slug")
90-
->click('Unsubscribe')
90+
->press('Unsubscribe')
9191
->seePageIs("/forum/$slug")
9292
->see("You're now unsubscribed from this thread.");
9393
});

0 commit comments

Comments
 (0)