rework components

This commit is contained in:
TimmensOne
2023-03-29 22:32:49 +02:00
parent 7a8e277887
commit 656056a3b3
17 changed files with 217 additions and 33 deletions

View File

@ -7,11 +7,19 @@ use App\Models\LocationTransaction;
use App\Models\PurchasingInformation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
class Device extends Model
{
use HasFactory;
/**
* The table associated with the model.
* @var string
*/
protected $table = 'devices';
/**
* The primary key associated with the devices table.
* @var string
@ -25,18 +33,20 @@ class Device extends Model
*/
protected $fillable = ['device_id', 'title', 'device_type', 'description', 'accessories', 'rz_username_buyer', 'serial_number', 'image_url'];
//The data type of the auto-incrementing ID.
protected $keyType = 'string';
//Timestamps are disabled.
public $timestamps = false;
public function owners() {
return $this->hasMany(OwnerTransaction::class, 'device_id');
public function owners(): HasMany {
return $this->hasMany(OwnerTransaction::class, 'device_id', 'device_id');
}
public function locations() {
return $this->hasMany(LocationTransaction::class, 'device_id');
public function locations(): HasMany {
return $this->hasMany(LocationTransaction::class, 'device_id', 'device_id');
}
public function purchasing() {
return $this->belongsTo(PurchasingInformation::class, 'device_id');
public function purchasing(): HasOne {
return $this->hasOne(PurchasingInformation::class, 'device_id', 'device_id');
}
}

View File

@ -5,11 +5,18 @@ namespace App\Models;
use App\Models\Device;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class LocationTransaction extends Model
{
use HasFactory;
/**
* The table associated with the model.
* @var string
*/
protected $table = 'location_transactions';
/**
* The primary key associated with the devices table.
* @var string
@ -23,7 +30,10 @@ class LocationTransaction extends Model
*/
protected $fillable = ['location_transaction_id', 'room_code', 'timestamp_located_since', 'device_id'];
public function device() {
return $this->belongsTo(Device::class, 'device_id');
public function device(): BelongsTo {
return $this->belongsTo(Device::class, 'device_id', 'device_id');
}
//Timestamps are disabled.
public $timestamps = false;
}

View File

@ -5,11 +5,18 @@ namespace App\Models;
use App\Models\Device;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class OwnerTransaction extends Model
{
use HasFactory;
/**
* The table associated with the model.
* @var string
*/
protected $table = 'owner_transactions';
/**
* The primary key associated with the devices table.
* @var string
@ -23,8 +30,10 @@ class OwnerTransaction extends Model
*/
protected $fillable = ['owner_transaction_id', 'rz_username', 'timestamp_owner_since', 'device_id'];
public function device() {
return $this->belongsTo(Device::class, 'device_id');
public function device(): BelongsTo {
return $this->belongsTo(Device::class, 'device_id', 'device_id');
}
//Timestamps are disabled.
public $timestamps = false;
}

View File

@ -4,11 +4,18 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PurchasingInformation extends Model
{
use HasFactory;
/**
* The table associated with the model.
* @var string
*/
protected $table = 'purchasing_information';
/**
* The primary key associated with the devices table.
* @var string
@ -22,7 +29,10 @@ class PurchasingInformation extends Model
*/
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');
public function device(): BelongsTo {
return $this->belongsTo(Device::class, 'device_id', 'device_id');
}
//Timestamps are disabled.
public $timestamps = false;
}

View File

@ -12,6 +12,12 @@ class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The table associated with the model.
* @var string
*/
protected $table = 'users';
/**
* The primary key associated with the users table.
* @var string
@ -31,6 +37,8 @@ class User extends Authenticatable
'hashed_password'
];
//ID is not auto-incrementing.
public $incrementing = false;
//Timestamps are disabled.
public $timestamps = false;

View File

@ -0,0 +1,29 @@
<?php
namespace App\View\Components;
use App\Models\LocationTransaction as ModelsLocationTransaction;
use Closure;
use Illuminate\View\Component;
use Illuminate\Contracts\View\View;
class LocationTransaction extends Component
{
/**
* Create a new component instance.
*/
public function __construct(
public ModelsLocationTransaction $location
)
{
//
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.location-transaction');
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\View\Components;
use App\Models\OwnerTransaction as ModelsOwnerTransaction;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class OwnerTransaction extends Component
{
/**
* Create a new component instance.
*/
public function __construct(
public ModelsOwnerTransaction $owner
)
{
//
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.owner-transaction');
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\View\Components;
use App\Models\Device;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class PurchasingInformation extends Component
{
/**
* Create a new component instance.
*/
public function __construct(
public Device $device
)
{}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.purchasing-information');
}
}