add foreign keys and extend models

This commit is contained in:
TimmensOne
2023-03-28 22:17:54 +02:00
parent d7aa2494bd
commit 7a8e277887
12 changed files with 136 additions and 12 deletions

View File

@ -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');
}
}

View 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');
}
}

View 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');
}
}

View 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');
}
}