39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?php
|
|
|
|
use App\Models\School;
|
|
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::create('schools', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('name');
|
|
$table->string('address')->nullable();
|
|
$table->string('city')->nullable();
|
|
$table->string('state')->nullable();
|
|
$table->integer('zip')->nullable();
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::table('users', function(Blueprint $table) {
|
|
$table->foreignIdFor(School::class)->nullable()->after('id')->constrained()->onUpdate('cascade')->onDelete('set null');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*/
|
|
public function down(): void
|
|
{
|
|
Schema::dropColumns('users','school_id');
|
|
Schema::dropIfExists('schools');
|
|
}
|
|
};
|