diff --git a/device-app/app/Models/Device.php b/device-app/app/Models/Device.php index bb38700..cce77db 100644 --- a/device-app/app/Models/Device.php +++ b/device-app/app/Models/Device.php @@ -2,8 +2,11 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use App\Models\OwnerTransaction; +use App\Models\LocationTransaction; +use App\Models\PurchasingInformation; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Factories\HasFactory; class Device extends Model { @@ -24,4 +27,16 @@ class Device extends Model //Timestamps are disabled. public $timestamps = false; + + public function owners() { + return $this->hasMany(OwnerTransaction::class, 'device_id'); + } + + public function locations() { + return $this->hasMany(LocationTransaction::class, 'device_id'); + } + + public function purchasing() { + return $this->belongsTo(PurchasingInformation::class, 'device_id'); + } } \ No newline at end of file diff --git a/device-app/app/Models/LocationTransaction.php b/device-app/app/Models/LocationTransaction.php new file mode 100644 index 0000000..2ca3e90 --- /dev/null +++ b/device-app/app/Models/LocationTransaction.php @@ -0,0 +1,29 @@ + + */ + protected $fillable = ['location_transaction_id', 'room_code', 'timestamp_located_since', 'device_id']; + + public function device() { + return $this->belongsTo(Device::class, 'device_id'); + } +} \ No newline at end of file diff --git a/device-app/app/Models/OwnerTransaction.php b/device-app/app/Models/OwnerTransaction.php new file mode 100644 index 0000000..faa5aeb --- /dev/null +++ b/device-app/app/Models/OwnerTransaction.php @@ -0,0 +1,30 @@ + + */ + protected $fillable = ['owner_transaction_id', 'rz_username', 'timestamp_owner_since', 'device_id']; + + public function device() { + return $this->belongsTo(Device::class, 'device_id'); + } + +} diff --git a/device-app/app/Models/PurchasingInformation.php b/device-app/app/Models/PurchasingInformation.php new file mode 100644 index 0000000..ba71300 --- /dev/null +++ b/device-app/app/Models/PurchasingInformation.php @@ -0,0 +1,28 @@ + + */ + protected $fillable = ['purchasing_information_id', 'price', 'timestamp_warranty_end', 'timestamp_purchase', 'cost_centre', 'seller', 'device_id']; + + public function device() { + return $this->belongsTo(Device::class, 'device_id'); + } +} diff --git a/device-app/database/migrations/2023_03_20_114828_create_location_transactions_table.php b/device-app/database/migrations/2023_03_20_114828_create_location_transactions_table.php index 6428fc7..a91c6b9 100644 --- a/device-app/database/migrations/2023_03_20_114828_create_location_transactions_table.php +++ b/device-app/database/migrations/2023_03_20_114828_create_location_transactions_table.php @@ -16,6 +16,7 @@ public function up(): void $table->string('room_code'); $table->string('timestamp_located_since'); $table->string('device_id'); + $table->foreign('device_id')->references('device_id')->on('devices'); }); } diff --git a/device-app/database/migrations/2023_03_20_114834_create_owner_transactions_table.php b/device-app/database/migrations/2023_03_20_114834_create_owner_transactions_table.php index fa46372..7d3c049 100644 --- a/device-app/database/migrations/2023_03_20_114834_create_owner_transactions_table.php +++ b/device-app/database/migrations/2023_03_20_114834_create_owner_transactions_table.php @@ -16,6 +16,7 @@ public function up(): void $table->string('rz_username'); $table->string('timestamp_owner_since'); $table->string('device_id'); + $table->foreign('device_id')->references('device_id')->on('devices'); }); } diff --git a/device-app/database/migrations/2023_03_20_114945_create_purchasing_information_table.php b/device-app/database/migrations/2023_03_20_114945_create_purchasing_information_table.php index b158973..0539e73 100644 --- a/device-app/database/migrations/2023_03_20_114945_create_purchasing_information_table.php +++ b/device-app/database/migrations/2023_03_20_114945_create_purchasing_information_table.php @@ -18,7 +18,8 @@ public function up(): void $table->string('timestamp_purchase'); $table->string('cost_centre'); $table->string('seller')->nullable(); - $table->string('device_id')->unique(); + $table->string('device_id'); + $table->foreign('device_id')->references('device_id')->on('devices'); }); } diff --git a/device-app/resources/views/components/device-card.blade.php b/device-app/resources/views/components/device-card.blade.php index dd691d8..eda7980 100644 --- a/device-app/resources/views/components/device-card.blade.php +++ b/device-app/resources/views/components/device-card.blade.php @@ -1,4 +1,14 @@ @props(['device'])
Owner: {{ $locationTransaction->room_code }}
+since: {{ $locationTransaction->timestamp_located_since }}
+Owner: {{ $ownerTransaction->rz_username }}
+since: {{ $ownerTransaction->timestamp_owner_since }}
+price: {{ $purchasingInformation->price }}
+timestamp_warranty_end: {{ $purchasingInformation->timestamp_warranty_end }}
+timestamp_purchase: {{ $purchasingInformation->timestamp_purchase }}
+cost_centre: {{ $purchasingInformation->cost_centre }}
+seller: {{ $purchasingInformation->seller }}
+