Skip to content

Commit 5eef0cc

Browse files
committed
add migrations and models
1 parent ed4c328 commit 5eef0cc

File tree

6 files changed

+84
-3
lines changed

6 files changed

+84
-3
lines changed

app/Models/Certificate.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,27 @@
22

33
namespace App\Models;
44

5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
56
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\SoftDeletes;
68

79
class Certificate extends Model
810
{
9-
//
11+
// use HasFactory;
12+
use SoftDeletes;
13+
14+
protected $fillable = [
15+
'stream_name','property_id','issue_date','next_due_date'
16+
];
17+
18+
public function property()
19+
{
20+
return $this->belongsTo(Property::class);
21+
}
22+
23+
public function notes()
24+
{
25+
return $this->morphMany(Note::class, 'model', 'model_type', 'model_id')
26+
->where('model_type', 'Certificate');
27+
}
1028
}

app/Models/Note.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
66

77
class Note extends Model
88
{
9-
//
9+
protected $fillable = ['model_type','model_id','note'];
10+
11+
public function model()
12+
{
13+
return $this->morphTo(null, 'model_type', 'model_id');
14+
}
1015
}

app/Models/Property.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,40 @@
22

33
namespace App\Models;
44

5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
56
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\SoftDeletes;
68

79
class Property extends Model
810
{
9-
//
11+
// use HasFactory;
12+
use SoftDeletes;
13+
14+
protected $fillable = [
15+
'organisation','property_type','parent_property_id','uprn',
16+
'address','town','postcode','live'
17+
];
18+
19+
public function parent()
20+
{
21+
return $this->belongsTo(Property::class, 'parent_property_id');
22+
}
23+
24+
public function children()
25+
{
26+
return $this->hasMany(Property::class, 'parent_property_id');
27+
}
28+
29+
public function certificates()
30+
{
31+
return $this->hasMany(Certificate::class);
32+
}
33+
34+
public function notes()
35+
{
36+
// polymorphic-ish via model_type/model_id
37+
return $this->morphMany(Note::class, 'model', 'model_type', 'model_id')
38+
->where('model_type', 'Property');
39+
}
1040
}
41+

database/migrations/2025_11_10_001656_create_properties_table.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ public function up(): void
1515
$table->id();
1616
$table->timestamps();
1717
});
18+
Schema::create('properties', function (Blueprint $table) {
19+
$table->id();
20+
$table->string('organisation');
21+
$table->string('property_type');
22+
$table->unsignedBigInteger('parent_property_id')->nullable();
23+
$table->string('uprn');
24+
$table->string('address');
25+
$table->string('town')->nullable();
26+
$table->string('postcode');
27+
$table->boolean('live')->default(true);
28+
$table->timestamps();
29+
$table->softDeletes();
30+
31+
$table->foreign('parent_property_id')
32+
->references('id')->on('properties')
33+
->nullOnDelete();
34+
});
1835
}
1936

2037
/**

database/migrations/2025_11_10_001746_create_certificates_table.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ public function up(): void
1313
{
1414
Schema::create('certificates', function (Blueprint $table) {
1515
$table->id();
16+
$table->string('stream_name');
17+
$table->foreignId('property_id')->constrained('properties')->cascadeOnDelete();
18+
$table->date('issue_date');
19+
$table->date('next_due_date');
1620
$table->timestamps();
21+
$table->softDeletes();
1722
});
1823
}
1924

database/migrations/2025_11_10_001755_create_notes_table.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ public function up(): void
1313
{
1414
Schema::create('notes', function (Blueprint $table) {
1515
$table->id();
16+
$table->string('model_type');
17+
$table->unsignedBigInteger('model_id');
18+
$table->text('note');
1619
$table->timestamps();
20+
21+
$table->index(['model_type', 'model_id']);
1722
});
1823
}
1924

0 commit comments

Comments
 (0)