Init
This commit is contained in:
33
database/migrations/2024_07_30_194424_fix_slugs.php
Normal file
33
database/migrations/2024_07_30_194424_fix_slugs.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Episode;
|
||||
use App\Models\Hentai;
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
foreach (Hentai::all() as $hentai) {
|
||||
$slugParts = explode('-', $hentai->slug);
|
||||
$lastPart = $slugParts[array_key_last($slugParts)];
|
||||
if (is_numeric($lastPart) && $lastPart < 1000) {
|
||||
$slugParts[array_key_last($slugParts)] = 's'.$lastPart;
|
||||
$newSlug = implode('-', $slugParts);
|
||||
|
||||
// Update hentai slug
|
||||
$hentai->slug = $newSlug;
|
||||
$hentai->save();
|
||||
|
||||
// Update episodes related to this hentai in bulk
|
||||
Episode::where('hentai_id', $hentai->id)
|
||||
->update(['slug' => DB::raw("CONCAT('$newSlug-', episode)")]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user