diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 3f41e093f9..2275824ce6 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -92,7 +92,7 @@ public function index(Request $request): \Illuminate\Contracts\View\Factory|\Ill 'latest_posts:by-group:'.auth()->user()->group_id, $expiresAt, fn () => Post::query() - ->with('user', 'user.group', 'topic:id,name') + ->with('user', 'user.group', 'topic:id,name', 'updatedBy.group') ->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics') ->withSum('tips', 'bon') ->withExists([ diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index c347ebbb58..b59c9b1670 100644 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -207,7 +207,8 @@ public function update(Request $request, int $id): \Illuminate\Http\RedirectResp abort_unless($post->topic()->authorized(canReplyTopic: true)->exists(), 403); $post->update([ - 'content' => $request->input('content'), + 'content' => $request->input('content'), + 'updated_by' => $user->id, ]); return redirect()->to($postUrl) diff --git a/app/Http/Controllers/User/PostController.php b/app/Http/Controllers/User/PostController.php index cc5505fb7d..538a3ac18d 100644 --- a/app/Http/Controllers/User/PostController.php +++ b/app/Http/Controllers/User/PostController.php @@ -29,7 +29,7 @@ public function index(User $user): \Illuminate\Contracts\View\Factory|\Illuminat return view('user.post.index', [ 'user' => $user, 'posts' => $user->posts() - ->with('user', 'user.group', 'topic:id,name,state') + ->with('user', 'user.group', 'topic:id,name,state', 'updatedBy.group') ->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics') ->withSum('tips', 'bon') ->authorized(canReadTopic: true) diff --git a/app/Http/Livewire/PostSearch.php b/app/Http/Livewire/PostSearch.php index fd23ee1c6a..84b40f687f 100644 --- a/app/Http/Livewire/PostSearch.php +++ b/app/Http/Livewire/PostSearch.php @@ -43,7 +43,7 @@ final public function updatingSearch(): void final public function posts(): \Illuminate\Pagination\LengthAwarePaginator { return Post::query() - ->with('user', 'user.group', 'topic:id,name,state') + ->with('user', 'user.group', 'topic:id,name,state', 'updatedBy.group') ->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics') ->withSum('tips', 'bon') ->withExists([ diff --git a/app/Http/Livewire/TopicPostSearch.php b/app/Http/Livewire/TopicPostSearch.php index 66062a82f0..f0bfa70f56 100644 --- a/app/Http/Livewire/TopicPostSearch.php +++ b/app/Http/Livewire/TopicPostSearch.php @@ -53,7 +53,7 @@ final public function updatingSearch(): void final public function posts(): \Illuminate\Pagination\LengthAwarePaginator { $posts = Post::query() - ->with('user', 'user.group') + ->with('user', 'user.group', 'updatedBy.group') ->withCount('likes', 'dislikes', 'authorPosts', 'authorTopics') ->withSum('tips', 'bon') ->where('topic_id', '=', $this->topic->id) diff --git a/app/Models/Post.php b/app/Models/Post.php index b8685614d3..be269b7e93 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -30,6 +30,7 @@ * @property string $content * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at + * @property int $updated_by * @property int $user_id * @property int $topic_id */ @@ -49,6 +50,7 @@ class Post extends Model 'content', 'topic_id', 'user_id', + 'updated_by', ]; /** @@ -74,6 +76,16 @@ public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo ]); } + /** + * Belongs To An Updated User. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function updatedBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(User::class, 'updated_by', 'id')->withTrashed(); + } + /** * A Post Has Many Likes. * diff --git a/database/migrations/2024_10_28_164054_add_edited_by_to_posts_table.php b/database/migrations/2024_10_28_164054_add_edited_by_to_posts_table.php new file mode 100644 index 0000000000..087247974f --- /dev/null +++ b/database/migrations/2024_10_28_164054_add_edited_by_to_posts_table.php @@ -0,0 +1,45 @@ + + * @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 + */ + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +return new class () extends Migration { + /** + * Run the migrations. + */ + public function up(): void + { + Schema::table('posts', function (Blueprint $table): void { + $table->unsignedInteger('updated_by')->nullable()->after('updated_at'); + $table->foreign('updated_by')->references('id')->on('users')->cascadeOnUpdate()->cascadeOnDelete(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::table('posts', function (Blueprint $table): void { + $table->dropForeign(['updated_by']); + $table->dropColumn('updated_by'); + }); + } +}; diff --git a/resources/sass/components/forum/_post.scss b/resources/sass/components/forum/_post.scss index dae1340602..2516ffd05d 100644 --- a/resources/sass/components/forum/_post.scss +++ b/resources/sass/components/forum/_post.scss @@ -38,8 +38,8 @@ .post__header { grid-area: header; display: grid; - grid-template-areas: 'datetime topic . tip-stats toolbar'; - grid-template-columns: auto auto 1fr auto auto; + grid-template-areas: 'datetime edited topic . tip-stats toolbar'; + grid-template-columns: auto auto auto 1fr auto auto; align-items: center; gap: 9px; font-size: 13px; @@ -52,6 +52,26 @@ grid-area: datetime; } +.post__edited { + grid-area: edited; + cursor: pointer; +} + +.post__edited-dropdown { + display: none; + background-color: var(--top-nav-dropdown-menu-item-hover-bg); + position: absolute; + padding: 5px; + box-shadow: var(--post-shadow); + border-radius: 5px; + border: var(--bbcode-input-border); +} + +/* Show dropdown menu when the dropdown is focused */ +.post__edited:hover .post__edited-dropdown { + display: block; +} + .post__topic { grid-area: topic; } @@ -158,6 +178,7 @@ background-color: transparent; color: var(--post-like-fg); } + .votes__dislike { background-color: transparent; color: var(--post-dislike-fg); @@ -289,8 +310,8 @@ } .post__header { - grid-template-areas: 'datetime topic . tip-stats overflow' '. . . . toolbar'; - grid-template-columns: auto auto 1fr auto auto; + grid-template-areas: 'datetime edited topic . tip-stats overflow' '. . . . toolbar'; + grid-template-columns: auto auto auto 1fr auto auto; gap: 0 6px; } @@ -358,10 +379,12 @@ -webkit-transform: scale(1); transform: scale(1); } + 50% { -webkit-transform: scale(1.1); transform: scale(1.1); } + 100% { -webkit-transform: scale(1); transform: scale(1); @@ -373,12 +396,14 @@ -webkit-transform: scale(1); transform: scale(1); } + 50% { -webkit-transform: scale(1.1); transform: scale(1.1); } + 100% { -webkit-transform: scale(1); transform: scale(1); } -} +} \ No newline at end of file diff --git a/resources/views/components/forum/post.blade.php b/resources/views/components/forum/post.blade.php index 396e8240cb..344addafa6 100644 --- a/resources/views/components/forum/post.blade.php +++ b/resources/views/components/forum/post.blade.php @@ -11,6 +11,26 @@ class="post__datetime" > {{ $post->created_at?->diffForHumans() }} + + @if ($post->updated_at > $post->created_at) + + • edited + +
+ {{ $post->updated_at?->diffForHumans() }} + by + + {{ $post->updatedBy?->username ?? $post->user->username }} + +
+
+ @endif + @if (! Route::is('topics.show')) {{ __('forum.in') }}