add foreign keys and extend models
This commit is contained in:
@ -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');
|
||||
}
|
||||
}
|
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');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user