File: /var/www/limestate-admin/database/migrations/2024_10_10_121000_add_street_to_complexes.php
<?php
use App\Models\Complex;
use App\Models\ComplexStreet;
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('complexes', function (Blueprint $table) {
$table->string('street_name')->after('city_id')->nullable();
});
/** @var ComplexStreet[] $complexStreets */
$complexStreets = ComplexStreet::query()->get();
foreach ($complexStreets as $complexStreet) {
Complex::query()->where('id', $complexStreet->complex_id)->update(['street_name' => $complexStreet->street_name]);
}
}
public function down(): void
{
Schema::table('complexes', function (Blueprint $table) {
$table->dropColumn(['street_name']);
});
}
};