add foreign keys and extend models
This commit is contained in:
parent
d7aa2494bd
commit
7a8e277887
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
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\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
class Device extends Model
|
class Device extends Model
|
||||||
{
|
{
|
||||||
@ -24,4 +27,16 @@ class Device extends Model
|
|||||||
|
|
||||||
//Timestamps are disabled.
|
//Timestamps are disabled.
|
||||||
public $timestamps = false;
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
29
device-app/app/Models/LocationTransaction.php
Normal file
29
device-app/app/Models/LocationTransaction.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Device;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
|
class LocationTransaction extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the devices table.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'location_transaction_id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
protected $fillable = ['location_transaction_id', 'room_code', 'timestamp_located_since', 'device_id'];
|
||||||
|
|
||||||
|
public function device() {
|
||||||
|
return $this->belongsTo(Device::class, 'device_id');
|
||||||
|
}
|
||||||
|
}
|
30
device-app/app/Models/OwnerTransaction.php
Normal file
30
device-app/app/Models/OwnerTransaction.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Device;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
|
class OwnerTransaction extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the devices table.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'owner_transaction_id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
protected $fillable = ['owner_transaction_id', 'rz_username', 'timestamp_owner_since', 'device_id'];
|
||||||
|
|
||||||
|
public function device() {
|
||||||
|
return $this->belongsTo(Device::class, 'device_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
28
device-app/app/Models/PurchasingInformation.php
Normal file
28
device-app/app/Models/PurchasingInformation.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class PurchasingInformation extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the devices table.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'purchasing_information_id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,7 @@ public function up(): void
|
|||||||
$table->string('room_code');
|
$table->string('room_code');
|
||||||
$table->string('timestamp_located_since');
|
$table->string('timestamp_located_since');
|
||||||
$table->string('device_id');
|
$table->string('device_id');
|
||||||
|
$table->foreign('device_id')->references('device_id')->on('devices');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ public function up(): void
|
|||||||
$table->string('rz_username');
|
$table->string('rz_username');
|
||||||
$table->string('timestamp_owner_since');
|
$table->string('timestamp_owner_since');
|
||||||
$table->string('device_id');
|
$table->string('device_id');
|
||||||
|
$table->foreign('device_id')->references('device_id')->on('devices');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@ public function up(): void
|
|||||||
$table->string('timestamp_purchase');
|
$table->string('timestamp_purchase');
|
||||||
$table->string('cost_centre');
|
$table->string('cost_centre');
|
||||||
$table->string('seller')->nullable();
|
$table->string('seller')->nullable();
|
||||||
$table->string('device_id')->unique();
|
$table->string('device_id');
|
||||||
|
$table->foreign('device_id')->references('device_id')->on('devices');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,14 @@
|
|||||||
@props(['device'])
|
@props(['device'])
|
||||||
<div>
|
<div>
|
||||||
<a href="/devices/{{ $device['device_id'] }}">{{ $device->title }}</a>
|
<a href="/devices/{{ $device['device_id'] }}">{{ $device->title }}</a>
|
||||||
|
<ul>
|
||||||
|
<li>{{ $device['device_id'] }}</li>
|
||||||
|
<li>{{ $device['title'] }}</li>
|
||||||
|
<li>{{ $device['device_type'] }}</li>
|
||||||
|
<li>{{ $device['description'] }}</li>
|
||||||
|
<li>{{ $device['accessories'] }}</li>
|
||||||
|
<li>{{ $device['rz_username_buyer'] }}</li>
|
||||||
|
<li>{{ $device['serial_number'] }}</li>
|
||||||
|
<li>{{ $device['image_url'] }}</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
@ -0,0 +1,5 @@
|
|||||||
|
@props(['locationTransaction'])
|
||||||
|
<div>
|
||||||
|
<p>Owner: {{ $locationTransaction->room_code }}</p>
|
||||||
|
<p>since: {{ $locationTransaction->timestamp_located_since }}</p>
|
||||||
|
</div>
|
@ -0,0 +1,5 @@
|
|||||||
|
@props(['ownerTransaction'])
|
||||||
|
<div>
|
||||||
|
<p>Owner: {{ $ownerTransaction->rz_username }}</p>
|
||||||
|
<p>since: {{ $ownerTransaction->timestamp_owner_since }}</p>
|
||||||
|
</div>
|
@ -0,0 +1,8 @@
|
|||||||
|
@props(['purchasingInformation'])
|
||||||
|
<div>
|
||||||
|
<p>price: {{ $purchasingInformation->price }}</p>
|
||||||
|
<p>timestamp_warranty_end: {{ $purchasingInformation->timestamp_warranty_end }}</p>
|
||||||
|
<p>timestamp_purchase: {{ $purchasingInformation->timestamp_purchase }}</p>
|
||||||
|
<p>cost_centre: {{ $purchasingInformation->cost_centre }}</p>
|
||||||
|
<p>seller: {{ $purchasingInformation->seller }}</p>
|
||||||
|
</div>
|
@ -2,16 +2,7 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<h1>Device Detail</h1>
|
<h1>Device Detail</h1>
|
||||||
<ul>
|
|
||||||
<li>{{ $device['device_id'] }}</li>
|
|
||||||
<li>{{ $device['title'] }}</li>
|
|
||||||
<li>{{ $device['device_type'] }}</li>
|
|
||||||
<li>{{ $device['description'] }}</li>
|
|
||||||
<li>{{ $device['accessories'] }}</li>
|
|
||||||
<li>{{ $device['rz_username_buyer'] }}</li>
|
|
||||||
<li>{{ $device['serial_number'] }}</li>
|
|
||||||
<li>{{ $device['image_url'] }}</li>
|
|
||||||
</ul>
|
|
||||||
<button><a href="{{$device->device_id}}/edit">Edit</a></button>
|
<button><a href="{{$device->device_id}}/edit">Edit</a></button>
|
||||||
|
|
||||||
<form method="POST" action="{{$device->device_id}}">
|
<form method="POST" action="{{$device->device_id}}">
|
||||||
|
Loading…
Reference in New Issue
Block a user