update: normalize forums a little more

We already make most of these queries anyways, and we'll need these foriegn keys when implementing future forum features like 'catch up'.
This commit is contained in:
Roardom
2024-02-08 18:08:49 +00:00
parent b823ade1b3
commit 834d438281
24 changed files with 243 additions and 191 deletions
@@ -39,9 +39,6 @@ class ForumCategoryController extends Controller
->withErrors('You Do Not Have Access To This Category!');
}
// Fetch topics->posts in descending order
// $topics = $forum->sub_topics()->latest('pinned')->latest('last_reply_at')->latest()->paginate(25);
return view('forum.category_topic.index', [
'forum' => $forum,
]);
+1
View File
@@ -34,6 +34,7 @@ class ForumController extends Controller
'forums' => fn ($query) => $query
->whereRelation('permissions', [['show_forum', '=', 1], ['group_id', '=', $request->user()->group_id]]),
'forums.latestPoster' => fn ($query) => $query->withTrashed(),
'forums.lastRepliedTopic',
])
->whereNull('parent_id')
->whereRelation('permissions', [['show_forum', '=', 1], ['group_id', '=', $request->user()->group_id]])
+23 -25
View File
@@ -82,20 +82,19 @@ class PostController extends Controller
]);
$topic->update([
'last_post_user_id' => $user->id,
'last_post_user_username' => $user->username,
'num_post' => $topic->posts()->count(),
'last_reply_at' => $post->created_at,
'last_post_id' => $post->id,
'last_post_user_id' => $user->id,
'num_post' => $topic->posts()->count(),
'last_post_created_at' => $post->created_at,
]);
$forum->update([
'num_post' => $forum->posts()->count(),
'num_topic' => $forum->topics()->count(),
'last_post_user_id' => $user->id,
'last_post_user_username' => $user->username,
'last_topic_id' => $topic->id,
'last_topic_name' => $topic->name,
'updated_at' => $post->created_at,
'num_post' => $forum->posts()->count(),
'num_topic' => $forum->topics()->count(),
'last_post_user_id' => $user->id,
'last_post_id' => $post->id,
'last_topic_id' => $topic->id,
'last_post_created_at' => $post->created_at,
]);
// Post To Chatbox and Notify Subscribers
@@ -229,7 +228,7 @@ class PostController extends Controller
$post->delete();
$latestPost = $topic->latestPost;
$latestPost = $topic->latestPostSlow;
$isTopicDeleted = false;
if ($latestPost === null) {
@@ -238,26 +237,25 @@ class PostController extends Controller
} else {
$latestPoster = $latestPost->user;
$topic->update([
'last_post_user_id' => $latestPoster->id,
'last_post_user_username' => $latestPoster->username,
'num_post' => $topic->posts()->count(),
'last_reply_at' => $latestPost->created_at,
'last_post_id' => $latestPost->id,
'last_post_user_id' => $latestPoster->id,
'num_post' => $topic->posts()->count(),
'last_post_created_at' => $latestPost->created_at,
]);
}
$forum = $topic->forum;
$lastRepliedTopic = $forum->lastRepliedTopic;
$latestPost = $lastRepliedTopic->latestPost;
$lastRepliedTopic = $forum->lastRepliedTopicSlow;
$latestPost = $lastRepliedTopic->latestPostSlow;
$latestPoster = $latestPost->user;
$forum->update([
'num_post' => $forum->posts()->count(),
'num_topic' => $forum->topics()->count(),
'last_post_user_id' => $latestPoster->id,
'last_post_user_username' => $latestPoster->username,
'last_topic_id' => $lastRepliedTopic->id,
'last_topic_name' => $lastRepliedTopic->name,
'updated_at' => $latestPost->created_at,
'num_post' => $forum->posts()->count(),
'num_topic' => $forum->topics()->count(),
'last_post_id' => $latestPost->id,
'last_post_user_id' => $latestPoster->id,
'last_topic_id' => $lastRepliedTopic->id,
'last_post_created_at' => $latestPost->created_at,
]);
if ($isTopicDeleted === true) {
+46 -48
View File
@@ -120,32 +120,34 @@ class TopicController extends Controller
->findOrFail($id);
$topic = Topic::create([
'name' => $request->title,
'state' => 'open',
'first_post_user_id' => $user->id,
'last_post_user_id' => $user->id,
'first_post_user_username' => $user->username,
'last_post_user_username' => $user->username,
'views' => 0,
'pinned' => false,
'forum_id' => $forum->id,
'num_post' => 1,
'last_reply_at' => now(),
'name' => $request->title,
'state' => 'open',
'first_post_user_id' => $user->id,
'last_post_user_id' => $user->id,
'views' => 0,
'pinned' => false,
'forum_id' => $forum->id,
'num_post' => 1,
]);
Post::create([
$post = Post::create([
'content' => $request->input('content'),
'user_id' => $user->id,
'topic_id' => $topic->id,
]);
$forum->update([
'num_topic' => $forum->topics()->count(),
'num_post' => $forum->posts()->count(),
'last_topic_id' => $topic->id,
'last_topic_name' => $topic->name,
'last_post_user_id' => $user->id,
'last_post_user_username' => $user->username,
'num_topic' => $forum->topics()->count(),
'num_post' => $forum->posts()->count(),
'last_topic_id' => $topic->id,
'last_post_id' => $post->id,
'last_post_user_id' => $user->id,
'last_post_created_at' => $post->created_at,
]);
$topic->update([
'last_post_id' => $post->id,
'last_post_created_at' => $post->created_at,
]);
// Post To ShoutBox
@@ -248,42 +250,39 @@ class TopicController extends Controller
]);
if ($oldForum->id === $newForum->id) {
$lastRepliedTopic = $newForum->lastRepliedTopic;
$lastRepliedTopic = $newForum->lastRepliedTopicSlow;
if ($lastRepliedTopic->id === $newForum->last_topic_id) {
$latestPost = $lastRepliedTopic->latestPost;
$latestPost = $lastRepliedTopic->latestPostSlow;
$newForum->last_topic_name = $request->name;
$newForum->updated_at = $latestPost->created_at;
$newForum->save();
}
} else {
$lastRepliedTopic = $oldForum->lastRepliedTopic;
$latestPost = $lastRepliedTopic->latestPost;
$lastRepliedTopic = $oldForum->lastRepliedTopicSlow;
$latestPost = $lastRepliedTopic->latestPostSlow;
$latestPoster = $latestPost->user;
$oldForum->update([
'num_topic' => $oldForum->topics()->count(),
'num_post' => $oldForum->posts()->count(),
'last_topic_id' => $lastRepliedTopic->id,
'last_topic_name' => $lastRepliedTopic->name,
'last_post_user_id' => $latestPoster->id,
'last_post_user_username' => $latestPoster->username,
'updated_at' => $latestPost->created_at,
'num_topic' => $oldForum->topics()->count(),
'num_post' => $oldForum->posts()->count(),
'last_topic_id' => $lastRepliedTopic->id,
'last_post_id' => $latestPost->id,
'last_post_user_id' => $latestPoster->id,
'last_post_created_at' => $latestPost->created_at,
]);
$lastRepliedTopic = $newForum->lastRepliedTopic;
$latestPost = $lastRepliedTopic->latestPost;
$lastRepliedTopic = $newForum->lastRepliedTopicSlow;
$latestPost = $lastRepliedTopic->latestPostSlow;
$latestPoster = $latestPost->user;
$newForum->update([
'num_topic' => $newForum->topics()->count(),
'num_post' => $newForum->posts()->count(),
'last_topic_id' => $lastRepliedTopic->id,
'last_topic_name' => $lastRepliedTopic->name,
'last_post_user_id' => $latestPoster->id,
'last_post_user_username' => $latestPoster->username,
'updated_at' => $latestPost->created_at,
'num_topic' => $newForum->topics()->count(),
'num_post' => $newForum->posts()->count(),
'last_topic_id' => $lastRepliedTopic->id,
'last_post_id' => $latestPost->id,
'last_post_user_id' => $latestPoster->id,
'last_post_created_at' => $latestPost->created_at,
]);
}
@@ -304,18 +303,17 @@ class TopicController extends Controller
$topic->delete();
$forum = $topic->forum;
$lastRepliedTopic = $forum->lastRepliedTopic;
$latestPost = $lastRepliedTopic->latestPost;
$lastRepliedTopic = $forum->lastRepliedTopicSlow;
$latestPost = $lastRepliedTopic->latestPostSlow;
$latestPoster = $latestPost->user;
$topic->forum()->update([
'num_topic' => $forum->topics()->count(),
'num_post' => $forum->posts()->count(),
'last_topic_id' => $lastRepliedTopic->id,
'last_topic_name' => $lastRepliedTopic->name,
'last_post_user_id' => $latestPoster->id,
'last_post_user_username' => $latestPoster->username,
'updated_at' => $latestPost->created_at,
'num_topic' => $forum->topics()->count(),
'num_post' => $forum->posts()->count(),
'last_topic_id' => $lastRepliedTopic->id,
'last_post_id' => $latestPost->id,
'last_post_user_id' => $latestPoster->id,
'last_post_created_at' => $latestPost->created_at,
]);
return to_route('forums.show', ['id' => $forum->id])
@@ -23,7 +23,7 @@ class ForumCategoryTopicSearch extends Component
use WithPagination;
public string $search = '';
public string $sortField = 'last_reply_at';
public string $sortField = 'last_post_created_at';
public string $sortDirection = 'desc';
public string $label = '';
public string $state = '';
@@ -35,7 +35,7 @@ class ForumCategoryTopicSearch extends Component
*/
protected $queryString = [
'search' => ['except' => ''],
'sortField' => ['except' => 'last_reply_at'],
'sortField' => ['except' => 'last_post_created_at'],
'sortDirection' => ['except' => 'desc'],
'label' => ['except' => ''],
'state' => ['except' => ''],
+2 -2
View File
@@ -24,7 +24,7 @@ class ForumTopicSearch extends Component
use WithPagination;
public string $search = '';
public string $sortField = 'last_reply_at';
public string $sortField = 'last_post_created_at';
public string $sortDirection = 'desc';
public string $label = '';
public string $state = '';
@@ -37,7 +37,7 @@ class ForumTopicSearch extends Component
*/
protected $queryString = [
'search' => ['except' => ''],
'sortField' => ['except' => 'last_reply_at'],
'sortField' => ['except' => 'last_post_created_at'],
'sortDirection' => ['except' => 'desc'],
'label' => ['except' => ''],
'state' => ['except' => ''],
+1 -1
View File
@@ -27,7 +27,7 @@ class SubscribedForum extends Component
final public function getForumsProperty()
{
return Forum::query()
->with('latestPoster')
->with('latestPoster', 'lastRepliedTopic')
->whereNotNull('parent_id')
->whereRelation('subscribedUsers', 'users.id', '=', auth()->id())
->whereRelation('permissions', [['show_forum', '=', 1], ['group_id', '=', auth()->user()->group_id]])
+2 -2
View File
@@ -28,10 +28,10 @@ class SubscribedTopic extends Component
{
return Topic::query()
->select('topics.*')
->with('user', 'user.group', 'latestPoster')
->with('user', 'user.group', 'latestPoster', 'forum')
->whereRelation('subscribedUsers', 'users.id', '=', auth()->id())
->whereRelation('forumPermissions', [['show_forum', '=', 1], ['group_id', '=', auth()->user()->group_id]])
->orderBy('last_reply_at')
->orderBy('last_post_created_at')
->paginate(25, ['*'], 'subscribedTopicsPage');
}
+3 -3
View File
@@ -23,7 +23,7 @@ class TopicSearch extends Component
use WithPagination;
public string $search = '';
public string $sortField = 'last_reply_at';
public string $sortField = 'last_post_created_at';
public string $sortDirection = 'desc';
public string $label = '';
public string $state = '';
@@ -35,7 +35,7 @@ class TopicSearch extends Component
*/
protected $queryString = [
'search' => ['except' => ''],
'sortField' => ['except' => 'last_reply_at'],
'sortField' => ['except' => 'last_post_created_at'],
'sortDirection' => ['except' => 'desc'],
'label' => ['except' => ''],
'state' => ['except' => ''],
@@ -75,7 +75,7 @@ class TopicSearch extends Component
{
return Topic::query()
->select('topics.*')
->with('user', 'user.group', 'latestPoster')
->with('user', 'user.group', 'latestPoster', 'forum')
->whereRelation('forumPermissions', [['show_forum', '=', 1], ['group_id', '=', auth()->user()->group_id]])
->when($this->search !== '', fn ($query) => $query->where('name', 'LIKE', '%'.$this->search.'%'))
->when($this->label !== '', fn ($query) => $query->where($this->label, '=', 1))
+14 -4
View File
@@ -26,9 +26,9 @@ use Illuminate\Database\Eloquent\Model;
* @property int|null $num_topic
* @property int|null $num_post
* @property int|null $last_topic_id
* @property string|null $last_topic_name
* @property int|null $last_post_id
* @property int|null $last_post_user_id
* @property string|null $last_post_user_username
* @property \Illuminate\Support\Carbon|null $last_post_created_at
* @property string|null $name
* @property string|null $slug
* @property string|null $description
@@ -105,9 +105,19 @@ class Forum extends Model
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne<Topic>
*/
public function lastRepliedTopic(): \Illuminate\Database\Eloquent\Relations\HasOne
public function lastRepliedTopicSlow(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(Topic::class)->ofMany('last_reply_at', 'max');
return $this->hasOne(Topic::class)->ofMany('last_post_created_at', 'max');
}
/**
* Latest topic.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<Topic, self>
*/
public function lastRepliedTopic(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Topic::class, 'last_post_topic_id');
}
/**
+24 -16
View File
@@ -34,10 +34,9 @@ use Illuminate\Database\Eloquent\Model;
* @property bool $implemented
* @property int|null $num_post
* @property int|null $first_post_user_id
* @property int|null $last_post_id
* @property int|null $last_post_user_id
* @property string|null $first_post_user_username
* @property string|null $last_post_user_username
* @property \Illuminate\Support\Carbon|null $last_reply_at
* @property \Illuminate\Support\Carbon|null $last_post_created_at
* @property int|null $views
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
@@ -49,15 +48,15 @@ class Topic extends Model
use HasFactory;
protected $casts = [
'last_reply_at' => 'datetime',
'pinned' => 'boolean',
'approved' => 'boolean',
'denied' => 'boolean',
'solved' => 'boolean',
'invalid' => 'boolean',
'bug' => 'boolean',
'suggestion' => 'boolean',
'implemented' => 'boolean',
'last_post_created_at' => 'datetime',
'pinned' => 'boolean',
'approved' => 'boolean',
'denied' => 'boolean',
'solved' => 'boolean',
'invalid' => 'boolean',
'bug' => 'boolean',
'suggestion' => 'boolean',
'implemented' => 'boolean',
];
protected $fillable = [
@@ -65,13 +64,12 @@ class Topic extends Model
'state',
'first_post_user_id',
'last_post_user_id',
'first_post_user_username',
'last_post_user_username',
'last_post_id',
'views',
'pinned',
'forum_id',
'num_post',
'last_reply_at',
'last_post_created_at',
];
/**
@@ -139,11 +137,21 @@ class Topic extends Model
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne<Post>
*/
public function latestPost(): \Illuminate\Database\Eloquent\Relations\HasOne
public function latestPostSlow(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(Post::class)->latestOfMany();
}
/**
* Latest post.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<Post, self>
*/
public function latestPost(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Post::class, 'last_post_id');
}
/**
* Latest poster.
*
+1 -1
View File
@@ -24,7 +24,7 @@ return [
'global_discards' => [
'password', 'passkey', 'rsskey', 'ip', 'remember_token',
'views', 'num_post', 'read', 'nfo',
'last_reply_at', 'last_action', 'created_at', 'updated_at', 'deleted_at',
'last_post_created_at', 'last_action', 'created_at', 'updated_at', 'deleted_at',
],
/*
+11 -12
View File
@@ -13,7 +13,6 @@
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Forum;
@@ -31,17 +30,17 @@ class ForumFactory extends Factory
public function definition(): array
{
return [
'position' => $this->faker->randomNumber(),
'num_topic' => $this->faker->randomNumber(),
'num_post' => $this->faker->randomNumber(),
'last_topic_id' => $this->faker->randomDigitNotNull(),
'last_topic_name' => $this->faker->word(),
'last_post_user_id' => User::factory(),
'last_post_user_username' => $this->faker->word(),
'name' => $this->faker->name(),
'slug' => $this->faker->slug(),
'description' => $this->faker->text(),
'parent_id' => $this->faker->randomDigitNotNull(),
'position' => $this->faker->randomNumber(),
'num_topic' => $this->faker->randomNumber(),
'num_post' => $this->faker->randomNumber(),
'last_topic_id' => null,
'last_post_id' => null,
'last_post_user_id' => null,
'last_post_created_at' => $this->faker->dateTime,
'name' => $this->faker->name(),
'slug' => $this->faker->slug(),
'description' => $this->faker->text(),
'parent_id' => $this->faker->randomDigitNotNull(),
];
}
}
+17 -19
View File
@@ -14,7 +14,6 @@
namespace Database\Factories;
use App\Models\Forum;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Topic;
@@ -32,24 +31,23 @@ class TopicFactory extends Factory
public function definition(): array
{
return [
'name' => $this->faker->name(),
'state' => $this->faker->word(),
'pinned' => $this->faker->boolean(),
'approved' => $this->faker->boolean(),
'denied' => $this->faker->boolean(),
'solved' => $this->faker->boolean(),
'invalid' => $this->faker->boolean(),
'bug' => $this->faker->boolean(),
'suggestion' => $this->faker->boolean(),
'implemented' => $this->faker->boolean(),
'num_post' => $this->faker->randomNumber(),
'first_post_user_id' => User::factory(),
'last_post_user_id' => User::factory(),
'first_post_user_username' => $this->faker->word(),
'last_post_user_username' => $this->faker->word(),
'last_reply_at' => $this->faker->dateTime(),
'views' => $this->faker->randomNumber(),
'forum_id' => Forum::factory(),
'name' => $this->faker->name(),
'state' => $this->faker->word(),
'pinned' => $this->faker->boolean(),
'approved' => $this->faker->boolean(),
'denied' => $this->faker->boolean(),
'solved' => $this->faker->boolean(),
'invalid' => $this->faker->boolean(),
'bug' => $this->faker->boolean(),
'suggestion' => $this->faker->boolean(),
'implemented' => $this->faker->boolean(),
'num_post' => $this->faker->randomNumber(),
'first_post_user_id' => null,
'last_post_id' => null,
'last_post_user_id' => null,
'last_post_created_at' => $this->faker->dateTime(),
'views' => $this->faker->randomNumber(),
'forum_id' => Forum::factory(),
];
}
}
@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
public function up(): void
{
Schema::table('topics', function (Blueprint $table): void {
$table->integer('last_post_id')->nullable()->after('first_post_user_id');
$table->dropColumn(['first_post_user_username', 'last_post_user_username']);
$table->foreign('last_post_id')->references('id')->on('posts')->cascadeOnUpdate()->nullOnDelete();
$table->renameColumn('last_reply_at', 'last_post_created_at');
$table->index('last_post_created_at');
});
DB::table('topics')
->update([
'last_post_id' => DB::raw('(SELECT MAX(id) FROM posts WHERE posts.topic_id = topics.id)'),
]);
Schema::table('forums', function (Blueprint $table): void {
$table->dropColumn(['last_topic_name', 'last_post_user_username']);
$table->integer('last_post_id')->nullable()->after('last_topic_id');
$table->timestamp('last_post_created_at')->nullable()->after('last_post_user_id')->index();
$table->foreign('last_post_id')->references('id')->on('posts')->cascadeOnUpdate()->nullOnDelete();
});
DB::table('forums')
->update([
'last_post_id' => DB::raw('(SELECT MAX(id) FROM posts WHERE posts.topic_id IN (SELECT id FROM topics WHERE forum_id = forums.id))'),
'last_post_created_at' => DB::raw('(SELECT MAX(created_at) FROM posts WHERE posts.topic_id IN (SELECT id FROM topics WHERE forum_id = forums.id))'),
]);
}
};
+28 -28
View File
@@ -22,36 +22,36 @@ class ForumsTableSeeder extends Seeder
{
Forum::upsert([
[
'id' => 1,
'position' => 1,
'num_topic' => null,
'num_post' => null,
'last_topic_id' => null,
'last_topic_name' => null,
'last_post_user_id' => null,
'last_post_user_username' => null,
'name' => 'UNIT3D Forums',
'slug' => 'unit3d-forums',
'description' => 'UNIT3D Forums',
'parent_id' => null,
'created_at' => '2017-01-03 18:29:21',
'updated_at' => '2017-01-03 18:29:21',
'id' => 1,
'position' => 1,
'num_topic' => null,
'num_post' => null,
'last_topic_id' => null,
'last_post_id' => null,
'last_post_user_id' => null,
'last_post_created_at' => null,
'name' => 'UNIT3D Forums',
'slug' => 'unit3d-forums',
'description' => 'UNIT3D Forums',
'parent_id' => null,
'created_at' => '2017-01-03 18:29:21',
'updated_at' => '2017-01-03 18:29:21',
],
[
'id' => 2,
'position' => 2,
'num_topic' => null,
'num_post' => null,
'last_topic_id' => null,
'last_topic_name' => null,
'last_post_user_id' => null,
'last_post_user_username' => null,
'name' => 'Welcome',
'slug' => 'welcome',
'description' => 'Introduce Yourself Here!',
'parent_id' => 1,
'created_at' => '2017-04-01 20:16:06',
'updated_at' => '2017-12-27 18:19:07',
'id' => 2,
'position' => 2,
'num_topic' => null,
'num_post' => null,
'last_topic_id' => null,
'last_post_id' => null,
'last_post_user_id' => null,
'last_post_created_at' => null,
'name' => 'Welcome',
'slug' => 'welcome',
'description' => 'Introduce Yourself Here!',
'parent_id' => 1,
'created_at' => '2017-04-01 20:16:06',
'updated_at' => '2017-12-27 18:19:07',
],
], ['id']);
}
@@ -28,13 +28,13 @@
<dd>{{ $subforum->num_post ?: 0 }}</dd>
</dl>
<article class="subforum-listing__latest-topic">
@if ($subforum->last_topic_id !== null && $subforum->last_topic_name !== null)
@if ($subforum->lastRepliedTopic !== null)
<p class="subforum-listing__latest-heading">
<a
class="subforum-listing__latest-link"
href="{{ route('topics.show', ['id' => $subforum->last_topic_id ?? 1]) }}"
href="{{ route('topics.show', ['id' => $subforum->lastRepliedTopic->id]) }}"
>
{{ $subforum->last_topic_name }}
{{ $subforum->lastRepliedTopic->name }}
</a>
</p>
@endif
@@ -44,24 +44,24 @@
datetime="{{ $subforum->updated_at }}"
title="{{ $subforum->updated_at }}"
>
@if ($subforum->last_topic_id === null)
@if ($subforum->lastRepliedTopic === null)
{{ $subforum->updated_at?->diffForHumans() ?? __('common.unknown') }}
@else
<a
class="subforum-listing__latest-post-link"
href="{{ route('topics.latestPermalink', ['id' => $subforum->last_topic_id]) }}"
href="{{ route('topics.latestPermalink', ['id' => $subforum->lastRepliedTopic->id]) }}"
>
{{ $subforum->updated_at?->diffForHumans() ?? __('common.unknown') }}
</a>
@endif
</time>
@if ($subforum->last_topic_id !== null && $subforum->latestPoster !== null)
@if ($subforum->lastRepliedTopic !== null && $subforum->latestPoster !== null)
<address class="subforum-listing__latest-author">
<a
class="subforum-listing__latest-author-link"
href="{{ route('users.show', ['user' => $subforum->latestPoster]) }}"
>
{{ $subforum->last_post_user_username }}
{{ $subforum->latestPoster->username }}
</a>
</address>
@endif
@@ -39,9 +39,13 @@
@endif
</ul>
<address class="topic-listing__author">
<a href="{{ route('users.show', ['user' => $topic->user]) }}">
{{ $topic->first_post_user_username }}
</a>
@if ($topic->user === null)
{{ __('common.unknown') }}
@else
<a href="{{ route('users.show', ['user' => $topic->user]) }}">
{{ $topic->user->username }}
</a>
@endif
</address>
</header>
<figure class="topic-listing__figure">
@@ -83,20 +87,20 @@
class="topic-listing__latest-author-link"
href="{{ route('users.show', ['user' => $topic->latestPoster]) }}"
>
{{ $topic->last_post_user_username }}
{{ $topic->latestPoster->username }}
</a>
@endif
</address>
<time
class="topic-listing__latest-datetime"
datetime="{{ $topic->last_reply_at }}"
title="{{ $topic->last_reply_at }}"
datetime="{{ $topic->last_post_created_at }}"
title="{{ $topic->last_post_created_at }}"
>
<a
class="topic-listing__latest-post-link"
href="{{ route('topics.latestPermalink', ['id' => $topic->id]) }}"
>
{{ $topic->last_reply_at?->diffForHumans() ?? __('common.unknown') }}
{{ $topic->last_post_created_at?->diffForHumans() ?? __('common.unknown') }}
</a>
</time>
</article>
+1 -1
View File
@@ -69,7 +69,7 @@
{{ __('common.unknown') }}
@else
<a href="{{ route('users.show', ['user' => $topic->user]) }}">
{{ $topic->first_post_user_username }}
{{ $topic->user->username }}
</a>
@endif
</dd>
@@ -71,7 +71,7 @@
required
wire:model="sortField"
>
<option value="last_reply_at">
<option value="last_post_created_at">
{{ __('forum.updated-at') }}
</option>
<option value="created_at">
@@ -124,7 +124,7 @@
required
wire:model="sortField"
>
<option value="last_reply_at">
<option value="last_post_created_at">
{{ __('forum.updated-at') }}
</option>
<option value="created_at">
@@ -94,7 +94,7 @@
required
wire:model="sortField"
>
<option value="last_reply_at">
<option value="last_post_created_at">
{{ __('forum.updated-at') }}
</option>
<option value="created_at">
@@ -36,10 +36,9 @@ test('show returns an ok response', function (): void {
$user = User::factory()->create();
$forum = Forum::factory()->create([
'parent_id' => null, // This Forum does not have a parent, which makes it a proper Forum and not a "Forum Category".
'last_post_user_id' => $user->id,
'last_post_user_username' => $user->username,
'last_topic_id' => null,
'parent_id' => null, // This Forum does not have a parent, which makes it a "Forum Category".
'last_post_user_id' => $user->id,
'last_topic_id' => null,
]);
Permission::factory()->create([
+2 -3
View File
@@ -75,9 +75,8 @@ final class ForumControllerTest extends TestCase
// (and not a "Forum Category").
$forum = Forum::factory()->create([
'parent_id' => 0,
'last_post_user_id' => $user->id,
'last_post_user_username' => $user->username,
'parent_id' => 0,
'last_post_user_id' => $user->id,
]);
$permissions = Permission::factory()->create([