Skip to content

Commit 0728f6b

Browse files
committed
Merge branch 'main' into fix/unsplash-api
2 parents 51c1d62 + f556b4a commit 0728f6b

File tree

13 files changed

+678
-553
lines changed

13 files changed

+678
-553
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: npm run build
3838

3939
- name: Execute tests
40-
run: vendor/bin/pest
40+
run: vendor/bin/pest -p
4141
env:
4242
DB_CONNECTION: mysql
4343
DB_COLLATION: utf8mb4_unicode_ci

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ We'd like to thank these **amazing companies** for sponsoring us. If you are int
2727
- [Skynet Technologies](https://www.skynettechnologies.com/hire-laravel-developer)
2828
- [BairesDev](https://www.bairesdev.com/sponsoring-open-source-projects/)
2929
- [Remotely Works](https://www.remotely.works/sponsoring-open-source-projects)
30-
- [Zunction](https://zunction.io)
3130
- [Dotcom-monitor](https://www.dotcom-monitor.com/sponsoring-open-source-projects/)
3231

3332
## Requirements

app/Http/Controllers/Forum/ThreadsController.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,14 @@ public function show(Thread $thread)
8181
return view('forum.threads.show', compact('thread', 'moderators'));
8282
}
8383

84-
public function create(): View
84+
public function create(): RedirectResponse|View
8585
{
86+
if (Auth::user()->hasTooManyThreadsToday()) {
87+
$this->error('You can only post a maximum of 5 threads per day.');
88+
89+
return redirect()->route('forum');
90+
}
91+
8692
$tags = Tag::all();
8793
$selectedTags = old('tags') ?: [];
8894

@@ -91,6 +97,12 @@ public function create(): View
9197

9298
public function store(ThreadRequest $request): RedirectResponse
9399
{
100+
if (Auth::user()->hasTooManyThreadsToday()) {
101+
$this->error('You can only post a maximum of 5 threads per day.');
102+
103+
return redirect()->route('forum');
104+
}
105+
94106
$this->dispatchSync(CreateThread::fromRequest($request, $uuid = Str::uuid()));
95107

96108
$thread = Thread::findByUuidOrFail($uuid);

app/Models/User.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Concerns\HasTimestamps;
66
use App\Concerns\PreparesSearch;
77
use App\Enums\NotificationType;
8+
use Carbon\Carbon;
89
use Illuminate\Contracts\Auth\MustVerifyEmail;
910
use Illuminate\Database\Eloquent\Builder;
1011
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -196,6 +197,20 @@ public function countThreads(): int
196197
return $this->threadsRelation()->count();
197198
}
198199

200+
public function countThreadsFromToday(): int
201+
{
202+
$today = Carbon::today();
203+
204+
return $this->threadsRelation()
205+
->whereBetween('created_at', [$today, $today->copy()->endOfDay()])
206+
->count();
207+
}
208+
209+
public function hasTooManyThreadsToday(): bool
210+
{
211+
return $this->countThreadsFromToday() >= 5;
212+
}
213+
199214
/**
200215
* @return \Illuminate\Database\Eloquent\Collection
201216
*/

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"fakerphp/faker": "^1.23",
4040
"mockery/mockery": "^1.6",
4141
"nunomaduro/collision": "^8.0",
42-
"pestphp/pest": "^2.23",
43-
"pestphp/pest-plugin-laravel": "^2.2"
42+
"pestphp/pest": "^3.0",
43+
"pestphp/pest-plugin-laravel": "^3.0"
4444
},
4545
"autoload": {
4646
"files": [

0 commit comments

Comments
 (0)