Skip to content

Commit

Permalink
fix: pinned questions updating updated_at
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Mar 22, 2024
1 parent 0d742e4 commit 82efc92
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Livewire/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function render(): View
return view('livewire.home', [
'questions' => Question::where('answer', '!=', null)
->where('is_reported', false)
->orderByDesc('answered_at')
->orderByDesc('updated_at')
->simplePaginate($this->perPage),
]);
}
Expand Down
7 changes: 5 additions & 2 deletions app/Livewire/Questions/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Models\Question;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Livewire\Attributes\Locked;
Expand Down Expand Up @@ -55,9 +56,11 @@ public function render(Request $request): View
'questions' => $user
->questionsReceived()
->where('is_reported', false)
->whereNotNull('answer')
->when(! $user->is($request->user()), function (Builder $query, bool $_): void { // @phpstan-ignore-line
$query->whereNotNull('answer');
})
->orderByDesc('pinned')
->orderByDesc('answered_at')
->orderByDesc('updated_at')
->simplePaginate($this->perPage),
]);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Livewire/Questions/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public function pin(): void

$this->authorize('pin', $question);

$user->pinnedQuestion()->update(['pinned' => false]);
$question->update(['pinned' => true]);
Question::withoutTimestamps(fn () => $user->pinnedQuestion()->update(['pinned' => false]));
Question::withoutTimestamps(fn () => $question->update(['pinned' => true]));

$this->dispatch('question.updated');
}
Expand All @@ -134,7 +134,7 @@ public function unpin(): void

$this->authorize('update', $question);

$question->update(['pinned' => false]);
Question::withoutTimestamps(fn () => $question->update(['pinned' => false]));

$this->dispatch('question.updated');
}
Expand Down

0 comments on commit 82efc92

Please sign in to comment.