From 7a8e27788795042f654faff47d468b7547b9de2a Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Tue, 28 Mar 2023 22:17:54 +0200 Subject: [PATCH] add foreign keys and extend models --- device-app/app/Models/Device.php | 17 ++++++++++- device-app/app/Models/LocationTransaction.php | 29 ++++++++++++++++++ device-app/app/Models/OwnerTransaction.php | 30 +++++++++++++++++++ .../app/Models/PurchasingInformation.php | 28 +++++++++++++++++ ...828_create_location_transactions_table.php | 1 + ...114834_create_owner_transactions_table.php | 1 + ...45_create_purchasing_information_table.php | 3 +- .../views/components/device-card.blade.php | 10 +++++++ .../components/device-location-card.blade.php | 5 ++++ .../components/device-owner-card.blade.php | 5 ++++ .../device-purchasing-card.blade.php | 8 +++++ .../resources/views/devices/show.blade.php | 11 +------ 12 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 device-app/app/Models/LocationTransaction.php create mode 100644 device-app/app/Models/OwnerTransaction.php create mode 100644 device-app/app/Models/PurchasingInformation.php create mode 100644 device-app/resources/views/components/device-location-card.blade.php create mode 100644 device-app/resources/views/components/device-owner-card.blade.php create mode 100644 device-app/resources/views/components/device-purchasing-card.blade.php 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'])
{{ $device->title }} +
\ No newline at end of file diff --git a/device-app/resources/views/components/device-location-card.blade.php b/device-app/resources/views/components/device-location-card.blade.php new file mode 100644 index 0000000..a32b7f4 --- /dev/null +++ b/device-app/resources/views/components/device-location-card.blade.php @@ -0,0 +1,5 @@ +@props(['locationTransaction']) +
+

Owner: {{ $locationTransaction->room_code }}

+

since: {{ $locationTransaction->timestamp_located_since }}

+
diff --git a/device-app/resources/views/components/device-owner-card.blade.php b/device-app/resources/views/components/device-owner-card.blade.php new file mode 100644 index 0000000..5f3e968 --- /dev/null +++ b/device-app/resources/views/components/device-owner-card.blade.php @@ -0,0 +1,5 @@ +@props(['ownerTransaction']) +
+

Owner: {{ $ownerTransaction->rz_username }}

+

since: {{ $ownerTransaction->timestamp_owner_since }}

+
\ No newline at end of file diff --git a/device-app/resources/views/components/device-purchasing-card.blade.php b/device-app/resources/views/components/device-purchasing-card.blade.php new file mode 100644 index 0000000..5e1679f --- /dev/null +++ b/device-app/resources/views/components/device-purchasing-card.blade.php @@ -0,0 +1,8 @@ +@props(['purchasingInformation']) +
+

price: {{ $purchasingInformation->price }}

+

timestamp_warranty_end: {{ $purchasingInformation->timestamp_warranty_end }}

+

timestamp_purchase: {{ $purchasingInformation->timestamp_purchase }}

+

cost_centre: {{ $purchasingInformation->cost_centre }}

+

seller: {{ $purchasingInformation->seller }}

+
\ No newline at end of file diff --git a/device-app/resources/views/devices/show.blade.php b/device-app/resources/views/devices/show.blade.php index e3958e2..5e1fea5 100644 --- a/device-app/resources/views/devices/show.blade.php +++ b/device-app/resources/views/devices/show.blade.php @@ -2,16 +2,7 @@ @section('content')

Device Detail

- +