abschlussprojekt-device-man.../device-app/app/Models/Device.php

52 lines
1.4 KiB
PHP
Raw Normal View History

2023-03-23 21:50:31 +01:00
<?php
namespace App\Models;
2023-03-28 22:17:54 +02:00
use App\Models\OwnerTransaction;
use App\Models\LocationTransaction;
use App\Models\PurchasingInformation;
2023-03-23 21:50:31 +01:00
use Illuminate\Database\Eloquent\Model;
2023-03-28 22:17:54 +02:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2023-03-29 22:32:49 +02:00
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
2023-03-23 21:50:31 +01:00
class Device extends Model
{
use HasFactory;
2023-03-29 22:32:49 +02:00
/**
* The table associated with the model.
* @var string
*/
protected $table = 'devices';
2023-03-24 13:49:09 +01:00
/**
* The primary key associated with the devices table.
2023-03-24 13:49:09 +01:00
* @var string
*/
protected $primaryKey = 'device_id';
2023-03-26 12:17:43 +02:00
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
2023-03-26 12:17:43 +02:00
protected $fillable = ['device_id', 'title', 'device_type', 'description', 'accessories', 'rz_username_buyer', 'serial_number', 'image_url'];
2023-03-29 22:32:49 +02:00
//The data type of the auto-incrementing ID.
protected $keyType = 'string';
//Timestamps are disabled.
public $timestamps = false;
2023-03-28 22:17:54 +02:00
2023-03-29 22:32:49 +02:00
public function owners(): HasMany {
return $this->hasMany(OwnerTransaction::class, 'device_id', 'device_id');
2023-03-28 22:17:54 +02:00
}
2023-03-29 22:32:49 +02:00
public function locations(): HasMany {
return $this->hasMany(LocationTransaction::class, 'device_id', 'device_id');
2023-03-28 22:17:54 +02:00
}
2023-03-29 22:32:49 +02:00
public function purchasing(): HasOne {
return $this->hasOne(PurchasingInformation::class, 'device_id', 'device_id');
2023-03-28 22:17:54 +02:00
}
2023-03-23 21:50:31 +01:00
}