Compare commits

...

2 Commits

2 changed files with 37 additions and 2 deletions
+7 -2
View File
@@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class InspectionTemplate extends Model
{
protected $fillable = ['name', 'description', 'project_id', 'fields'];
protected $fillable = ['name', 'description', 'project_id', 'phase_id', 'fields'];
protected $casts = ['fields' => 'array'];
@@ -15,8 +15,13 @@ class InspectionTemplate extends Model
return $this->belongsTo(Project::class);
}
public function phase()
{
return $this->belongsTo(Phase::class);
}
public function inspections()
{
return $this->hasMany(Inspection::class);
}
}
}
@@ -0,0 +1,30 @@
<?php
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::table('inspection_templates', function (Blueprint $table) {
$table->foreignId('phase_id')->nullable()->constrained('phases')->onDelete('set null');
$table->index('phase_id');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('inspection_templates', function (Blueprint $table) {
$table->dropForeign(['phase_id']);
$table->dropColumn('phase_id');
});
}
};