This commit is contained in:
ct
2025-07-16 23:33:43 +08:00
parent a1f17325f1
commit ade86ef772
8 changed files with 266 additions and 200 deletions

View File

@@ -90,6 +90,22 @@ public function show(string $slug): Response
->limit(6)
->get();
// If we have less than 6 related memes, fill up with random ones
if ($relatedMemes->count() < 6) {
$excludeIds = $relatedMemes->pluck('id')->push($meme->id)->toArray();
$needed = 6 - $relatedMemes->count();
$randomMemes = MemeMedia::where('is_enabled', true)
->whereNotIn('id', $excludeIds)
->inRandomOrder()
->limit($needed)
->get();
$relatedMemes = $relatedMemes->merge($randomMemes);
}
//dd($meme);
return Inertia::render('memes/show', [
'meme' => $meme,
'relatedMemes' => $relatedMemes,

View File

@@ -80,7 +80,7 @@ class MemeMedia extends Model
'type',
'sub_type',
'original_id',
'description',
//'description',
'mov_uuid',
'webm_uuid',
'gif_uuid',
@@ -98,7 +98,7 @@ class MemeMedia extends Model
protected function ids(): Attribute
{
return Attribute::make(
get: fn ($value, $attributes) => hashids_encode($attributes['id']),
get: fn($value, $attributes) => hashids_encode($attributes['id']),
);
}
}