implement uuid and make sample data factory

This commit is contained in:
TimmensOne 2023-03-30 15:16:38 +02:00
parent 656056a3b3
commit 6894c2c3c5
25 changed files with 202 additions and 81 deletions

View File

@ -22,7 +22,7 @@ public function create(){
public function store(Request $request){
$formFields = $request->validate([
'device_id' => ['required', Rule::unique('devices', 'device_id')],
//'device_id' => ['required', Rule::unique('devices', 'device_id')],
'title' => 'required',
'device_type' => 'required',
'description' => 'required',
@ -43,7 +43,7 @@ public function edit(Device $device) {
public function update(Device $device, Request $request){
$formFields = $request->validate([
'device_id' => 'required',
//'device_id' => 'required',
'title' => 'required',
'device_type' => 'required',
'description' => 'required',

View File

@ -5,6 +5,7 @@
use App\Models\OwnerTransaction;
use App\Models\LocationTransaction;
use App\Models\PurchasingInformation;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
@ -12,7 +13,7 @@
class Device extends Model
{
use HasFactory;
use HasFactory, HasUuids;
/**
* The table associated with the model.
@ -31,7 +32,7 @@ class Device extends Model
*
* @var array<int, string>
*/
protected $fillable = ['device_id', 'title', 'device_type', 'description', 'accessories', 'rz_username_buyer', 'serial_number', 'image_url'];
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';

View File

@ -3,13 +3,14 @@
namespace App\Models;
use App\Models\Device;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class LocationTransaction extends Model
{
use HasFactory;
use HasFactory, HasUuids;
/**
* The table associated with the model.

View File

@ -3,13 +3,14 @@
namespace App\Models;
use App\Models\Device;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class OwnerTransaction extends Model
{
use HasFactory;
use HasFactory, HasUuids;
/**
* The table associated with the model.

View File

@ -2,13 +2,14 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PurchasingInformation extends Model
{
use HasFactory;
use HasFactory, HasUuids;
/**
* The table associated with the model.

View File

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

View File

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

View File

@ -17,7 +17,7 @@ class DeviceFactory extends Factory
public function definition(): array
{
return [
'device_id' => $this->faker->randomDigitNotNull(),
'device_id' => $this->faker->uuid(),
'title' => $this->faker->word(),
'device_type' => $this->faker->domainWord(),
'description' => $this->faker->sentence(),

View File

@ -0,0 +1,24 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\LocationTransaction>
*/
class LocationTransactionFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'room_code' => $this->faker->buildingNumber(),
'timestamp_located_since' => $this->faker->unixTime()
];
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\OwnerTransaction>
*/
class OwnerTransactionFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'rz_username' => $this->faker->name(),
'timestamp_owner_since' => $this->faker->unixTime()
];
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PurchasingInformation>
*/
class PurchasingInformationFactory extends Factory
{
/**
* Define the model's default state.
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'price' => $this->faker->word(),
'timestamp_warranty_end' => $this->faker->unixTime(),
'timestamp_purchase' => $this->faker->unixTime(),
'cost_centre' => $this->faker->numberBetween(1000000000, 9999999999),
'seller' => $this->faker->company()
];
}
}

View File

@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('devices', function (Blueprint $table) {
$table->string('device_id')->unique();
$table->uuid('device_id')->primary();
$table->string('title');
$table->string('device_type');
$table->string('description')->nullable();

View File

@ -12,11 +12,10 @@
public function up(): void
{
Schema::create('location_transactions', function (Blueprint $table) {
$table->string('location_transaction_id')->unique();
$table->uuid('location_transaction_id')->primary();
$table->string('room_code');
$table->string('timestamp_located_since');
$table->string('device_id');
$table->foreign('device_id')->references('device_id')->on('devices');
$table->foreignUUid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete();
});
}

View File

@ -12,11 +12,10 @@
public function up(): void
{
Schema::create('owner_transactions', function (Blueprint $table) {
$table->string('owner_transaction_id')->unique();
$table->uuid('owner_transaction_id')->primary();
$table->string('rz_username');
$table->string('timestamp_owner_since');
$table->string('device_id');
$table->foreign('device_id')->references('device_id')->on('devices');
$table->foreignUuid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete();
});
}

View File

@ -12,14 +12,13 @@
public function up(): void
{
Schema::create('purchasing_information', function (Blueprint $table) {
$table->string('purchasing_information_id')->unique();
$table->uuid('purchasing_information_id')->primary();
$table->string('price');
$table->string('timestamp_warranty_end');
$table->string('timestamp_purchase');
$table->string('cost_centre');
$table->string('seller')->nullable();
$table->string('device_id');
$table->foreign('device_id')->references('device_id')->on('devices');
$table->foreignUuid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete();
});
}

View File

@ -25,12 +25,15 @@ public function run(): void
// 'email' => 'test@example.com',
// ]);
Device::factory(1)->create([
'device_id' => '1'
]);
//Device::factory()->has(PurchasingInformation::factory()->count(1))->create();
Device::factory()->count(10)
->has(PurchasingInformation::factory()->count(1), 'purchasing')
->has(LocationTransaction::factory()->count(3), 'locations')
->has(OwnerTransaction::factory()->count(3), 'owners')
->create();
User::create([
'rz_username' => 'admin',
'full_name' => 'Admin',
'organisation_unit' => '11111111',
@ -45,29 +48,5 @@ public function run(): void
'has_admin_privileges' => false,
'hashed_password' => bcrypt('test123')
]);
PurchasingInformation::create([
'purchasing_information_id' => '1',
'price' => '1',
'timestamp_warranty_end' => '1',
'timestamp_purchase' => '1',
'cost_centre' => '1',
'seller' => '1',
'device_id' => '1',
]);
LocationTransaction::create([
'location_transaction_id' => '1',
'room_code' => '1',
'timestamp_located_since' => '1',
'device_id' => '1',
]);
OwnerTransaction::create([
'owner_transaction_id' => '1',
'rz_username' => '1',
'timestamp_owner_since' => '1',
'device_id' => '1',
]);
}
}

View File

@ -1,25 +0,0 @@
@props(['device'])
<div>
<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>
<x-purchasing-information :device="$device" />
@php
$locationTransactions = $device->locations;
$ownerTransactins = $device->owners;
@endphp
@foreach ($locationTransactions as $location)
<x-location-transaction :location="$location" />
@endforeach
@foreach ($ownerTransactins as $owner)
<x-owner-transaction :owner="$owner" />
@endforeach
</div>

View File

@ -0,0 +1,27 @@
@props(['device'])
<div>
<h3>Device Detail</h3>
<ul>
<!--li>device_id: {{ $device['device_id'] }}</li-->
<li>title: {{ $device['title'] }}</li>
<li>device_type: {{ $device['device_type'] }}</li>
<li>description: {{ $device['description'] }}</li>
<li>accessories: {{ $device['accessories'] }}</li>
<li>rz_username_buyer: {{ $device['rz_username_buyer'] }}</li>
<li>serial_number: {{ $device['serial_number'] }}</li>
<li>image_url: {{ $device['image_url'] }}</li>
</ul>
<x-purchasing-information :device="$device" />
@php
$locationTransactions = $device->locations;
$ownerTransactins = $device->owners;
@endphp
<h3>Location Transactions</h3>
@foreach ($locationTransactions as $location)
<x-location-transaction :location="$location" />
@endforeach
<h3>Owner Transactions</h3>
@foreach ($ownerTransactins as $owner)
<x-owner-transaction :owner="$owner" />
@endforeach
</div>

View File

@ -0,0 +1,16 @@
@props(['device'])
<div>
<a href="/devices/{{ $device['device_id'] }}">{{ $device->title }}</a>
<ul>
<!--li>{{ $device['device_id'] }}</li-->
<!--li>title:{{ $device['title'] }}</li-->
<li>device_type: {{ $device['device_type'] }}</li>
<li>description: {{ $device['description'] }}</li>
<li>accessories: {{ $device['accessories'] }}</li>
<li>rz_username_buyer: {{ $device['rz_username_buyer'] }}</li>
<li>serial_number: {{ $device['serial_number'] }}</li>
<li>image_url: {{ $device['image_url'] }}</li>
<li>room_code: {{ $device->locations->last()['room_code'] }}</li>
<li>rz_username: {{ $device->owners->last()['rz_username'] }}</li>
</ul>
</div>

View File

@ -1,5 +1,4 @@
<div>
<h3>Location Transactions</h3>
<ul>
<li>room_code: {{ $location->room_code }}</li>
<li>timestamp_located_since: {{ $location->timestamp_located_since }}</li>

View File

@ -1,5 +1,4 @@
<div>
<h3>Owner Transactions</h3>
<ul>
<li>rz_username: {{ $owner->rz_username }}</li>
<li>timestamp_owner_since: {{ $owner->timestamp_owner_since }}</li>

View File

@ -3,12 +3,12 @@
@section('content')
<form method="POST" action="/devices">
@csrf
<label for="device_id">device_id:</label>
<!--label for="device_id">device_id:</label>
<input type="text" id="device_id" name="device_id" value="{{old('device_id')}}" required>
@error('device_id')
<p>{{$message}}</p>
@enderror
<br />
<br /-->
<label for="title">Title:</label>
<input type="text" id="title" name="title" value="{{old('title')}}" required>
@error('device_id')

View File

@ -4,12 +4,12 @@
<form method="POST" action="/devices/{{$device->device_id}}">
@method('PUT')
@csrf
<label for="device_id">device_id:</label>
<!--label for="device_id">device_id:</label>
<input type="text" id="device_id" name="device_id" value="{{$device->device_id}}" required>
@error('device_id')
<p>{{$message}}</p>
@enderror
<br />
<br /-->
<label for="title">Title:</label>
<input type="text" id="title" name="title" value="{{$device->title}}" required>
@error('device_id')

View File

@ -5,7 +5,7 @@
@unless(count($devices) == 0)
<ul>
@foreach ($devices as $device)
<x-device-card :device="$device" />
<x-device-simple :device="$device" />
@endforeach
</ul>
@else

View File

@ -1,10 +1,9 @@
@extends('layout')
@section('content')
<h1>Device Detail</h1>
<button><a href="{{$device->device_id}}/edit">Edit</a></button>
<x-device-detail :device="$device" />
<button><a href="{{$device->device_id}}/edit">Edit</a></button>
<form method="POST" action="{{$device->device_id}}">
@method('DELETE')
@csrf