Merge branch 'device-components' into 'main'

Device components

See merge request ase22ws/abschlussprojekt-device-manager-timon-lorenz!3
This commit is contained in:
lot17014 2023-03-31 12:22:51 +02:00
commit 7a95a3d36f
40 changed files with 785 additions and 51 deletions

View File

@ -35,3 +35,6 @@ sail exec laravel.test php artisan migrate:refresh --seed
## ChatGPT ## ChatGPT
see ChatGPT folder see ChatGPT folder
#### Challenges
Convention, due to given database. Could be easier

View File

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

View File

@ -0,0 +1,51 @@
<?php
namespace App\Http\Controllers;
use App\Models\Device;
use Illuminate\Http\Request;
use App\Models\LocationTransaction;
class LocationTransactionController extends Controller
{
public function create(Device $device)
{
return view('locations.create', ['device' => $device]);
}
public function store(Device $device, Request $request)
{
$formFields = $request->validate([
'room_code' => 'required',
'timestamp_located_since' => 'required'
]);
$formFields['device_id'] = $device->device_id;
LocationTransaction::create($formFields);
return redirect('/');
}
public function edit(LocationTransaction $location)
{
return view('locations.edit', ['location' => $location]);
}
public function update(LocationTransaction $location, Request $request)
{
$formFields = $request->validate([
'room_code' => 'required',
'timestamp_located_since' => 'required'
]);
$location->update($formFields);
return redirect('/');
}
public function destroy(LocationTransaction $location)
{
$location->delete();
return back();
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace App\Http\Controllers;
use App\Models\Device;
use App\Models\OwnerTransaction;
use Illuminate\Http\Request;
class OwnerTransactionController extends Controller
{
public function create(Device $device)
{
return view('owners.create', ['device' => $device]);
}
public function store(Device $device, Request $request)
{
$formFields = $request->validate([
'rz_username' => 'required',
'timestamp_owner_since' => 'required'
]);
$formFields['device_id'] = $device->device_id;
OwnerTransaction::create($formFields);
return redirect('/');
}
public function edit(OwnerTransaction $owner)
{
return view('owners.edit', ['owner' => $owner]);
}
public function update(OwnerTransaction $owner, Request $request)
{
$formFields = $request->validate([
'rz_username' => 'required',
'timestamp_owner_since' => 'required'
]);
$owner->update($formFields);
return redirect('/');
}
public function destroy(OwnerTransaction $owner)
{
$owner->delete();
return back();
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace App\Http\Controllers;
use App\Models\Device;
use App\Models\PurchasingInformation;
use Illuminate\Http\Request;
class PurchasingInformationController extends Controller
{
public function create()
{
return view('purchasings.create');
}
public function store(Request $request)
{
$formFields = $request->validate([
'price' => 'required',
'timestamp_warranty_end' => 'required',
'timestamp_purchase' => 'required',
'cost_centre' => 'required',
]);
PurchasingInformation::create($formFields);
return redirect('/');
}
public function edit(Device $device)
{
return view('purchasings.edit', ['purchasing' => $device->purchasing]);
}
public function update(Device $device, Request $request)
{
$formFields = $request->validate([
'price' => 'required',
'timestamp_warranty_end' => 'required',
'timestamp_purchase' => 'required',
'cost_centre' => 'required',
]);
$device->purchasing->update($formFields);
return redirect('/');
}
public function destroy(PurchasingInformation $purchasing)
{
$purchasing->delete();
return back();
}
}

View File

@ -2,12 +2,24 @@
namespace App\Models; 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\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model; 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 class Device extends Model
{ {
use HasFactory; use HasFactory, HasUuids;
/**
* The table associated with the model.
* @var string
*/
protected $table = 'devices';
/** /**
* The primary key associated with the devices table. * The primary key associated with the devices table.
@ -20,8 +32,22 @@ class Device extends Model
* *
* @var array<int, string> * @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';
//Timestamps are disabled. //Timestamps are disabled.
public $timestamps = false; public $timestamps = false;
public function owners(): HasMany {
return $this->hasMany(OwnerTransaction::class, 'device_id', 'device_id');
}
public function locations(): HasMany {
return $this->hasMany(LocationTransaction::class, 'device_id', 'device_id');
}
public function purchasing(): HasOne {
return $this->hasOne(PurchasingInformation::class, 'device_id', 'device_id');
}
} }

View File

@ -0,0 +1,40 @@
<?php
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, HasUuids;
/**
* The table associated with the model.
* @var string
*/
protected $table = 'location_transactions';
/**
* 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(): BelongsTo {
return $this->belongsTo(Device::class, 'device_id', 'device_id');
}
//Timestamps are disabled.
public $timestamps = false;
}

View File

@ -0,0 +1,40 @@
<?php
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, HasUuids;
/**
* The table associated with the model.
* @var string
*/
protected $table = 'owner_transactions';
/**
* 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(): BelongsTo {
return $this->belongsTo(Device::class, 'device_id', 'device_id');
}
//Timestamps are disabled.
public $timestamps = false;
}

View File

@ -0,0 +1,39 @@
<?php
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, HasUuids;
/**
* The table associated with the model.
* @var string
*/
protected $table = 'purchasing_information';
/**
* 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(): 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; use HasApiTokens, HasFactory, Notifiable;
/**
* The table associated with the model.
* @var string
*/
protected $table = 'users';
/** /**
* The primary key associated with the users table. * The primary key associated with the users table.
* @var string * @var string
@ -31,6 +37,8 @@ class User extends Authenticatable
'hashed_password' 'hashed_password'
]; ];
//ID is not auto-incrementing.
public $incrementing = false;
//Timestamps are disabled. //Timestamps are disabled.
public $timestamps = false; public $timestamps = false;

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

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

View File

@ -17,7 +17,7 @@ class DeviceFactory extends Factory
public function definition(): array public function definition(): array
{ {
return [ return [
'device_id' => $this->faker->randomDigitNotNull(), 'device_id' => $this->faker->uuid(),
'title' => $this->faker->word(), 'title' => $this->faker->word(),
'device_type' => $this->faker->domainWord(), 'device_type' => $this->faker->domainWord(),
'description' => $this->faker->sentence(), '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 public function up(): void
{ {
Schema::create('devices', function (Blueprint $table) { Schema::create('devices', function (Blueprint $table) {
$table->string('device_id')->unique(); $table->uuid('device_id')->primary();
$table->string('title'); $table->string('title');
$table->string('device_type'); $table->string('device_type');
$table->string('description')->nullable(); $table->string('description')->nullable();

View File

@ -12,10 +12,10 @@
public function up(): void public function up(): void
{ {
Schema::create('location_transactions', function (Blueprint $table) { 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('room_code');
$table->string('timestamp_located_since'); $table->string('timestamp_located_since');
$table->string('device_id'); $table->foreignUUid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete();
}); });
} }

View File

@ -12,10 +12,10 @@
public function up(): void public function up(): void
{ {
Schema::create('owner_transactions', function (Blueprint $table) { 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('rz_username');
$table->string('timestamp_owner_since'); $table->string('timestamp_owner_since');
$table->string('device_id'); $table->foreignUuid('device_id')->references('device_id')->on('devices')->cascadeOnUpdate()->cascadeOnDelete();
}); });
} }

View File

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

View File

@ -7,6 +7,9 @@
use App\Models\Device; use App\Models\Device;
use App\Models\User; use App\Models\User;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use App\Models\OwnerTransaction;
use App\Models\LocationTransaction;
use App\Models\PurchasingInformation;
class DatabaseSeeder extends Seeder class DatabaseSeeder extends Seeder
{ {
@ -22,10 +25,15 @@ public function run(): void
// 'email' => 'test@example.com', // 'email' => 'test@example.com',
// ]); // ]);
Device::factory(2)->create(); //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([ User::create([
'rz_username' => 'admin', 'rz_username' => 'admin',
'full_name' => 'Admin', 'full_name' => 'Admin',
'organisation_unit' => '11111111', 'organisation_unit' => '11111111',

View File

@ -1,4 +0,0 @@
@props(['device'])
<div>
<a href="/devices/{{ $device['device_id'] }}">{{ $device->title }}</a>
</div>

View File

@ -0,0 +1,35 @@
@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>
<button><a href="{{ $device->device_id }}/edit">Edit</a></button>
<form method="POST" action="{{ $device->device_id }}">
@method('DELETE')
@csrf
<button>Delete</button>
</form>
<x-purchasing-information :device="$device" />
@php
$locationTransactions = $device->locations;
$ownerTransactins = $device->owners;
@endphp
<h3>Location Transactions</h3>
<button><a href="{{ $device->device_id }}/locations/create">New Location</a></button>
@foreach ($locationTransactions as $location)
<x-location-transaction :location="$location" />
@endforeach
<h3>Owner Transactions</h3>
<button><a href="{{ $device->device_id }}/owners/create">New Owner</a></button>
@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

@ -0,0 +1,12 @@
<div>
<ul>
<li>room_code: {{ $location->room_code }}</li>
<li>timestamp_located_since: {{ $location->timestamp_located_since }}</li>
</ul>
<button><a href="locations/{{ $location->location_transaction_id }}/edit">Edit</a></button>
<form method="POST" action="locations/{{ $location->location_transaction_id }}">
@method('DELETE')
@csrf
<button>Delete</button>
</form>
</div>

View File

@ -0,0 +1,12 @@
<div>
<ul>
<li>rz_username: {{ $owner->rz_username }}</li>
<li>timestamp_owner_since: {{ $owner->timestamp_owner_since }}</li>
</ul>
<button><a href="owners/{{ $owner->owner_transaction_id }}/edit">Edit</a></button>
<form method="POST" action="owners/{{ $owner->owner_transaction_id }}">
@method('DELETE')
@csrf
<button>Delete</button>
</form>
</div>

View File

@ -0,0 +1,14 @@
<div>
@php
$purchasing = $device->purchasing;
@endphp
<h3>Purchasing Information</h3>
<ul>
<li>price: {{ $purchasing->price }}</li>
<li>timestamp_warranty_end: {{ $purchasing->timestamp_warranty_end }}</li>
<li>timestamp_purchase: {{ $purchasing->timestamp_purchase }}</li>
<li>cost_centre: {{ $purchasing->cost_centre }}</li>
<li>seller: {{ $purchasing->seller }}</li>
</ul>
<button><a href="{{ $device->device_id }}/purchasing/edit">Edit</a></button>
</div>

View File

@ -3,51 +3,51 @@
@section('content') @section('content')
<form method="POST" action="/devices"> <form method="POST" action="/devices">
@csrf @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> <input type="text" id="device_id" name="device_id" value="{{old('device_id')}}" required>
@error('device_id') @error('device_id')
<p>{{$message}}</p> <p>{{$message}}</p>
@enderror @enderror
<br /> <br /-->
<label for="title">Title:</label> <label for="title">Title:</label>
<input type="text" id="title" name="title" value="{{old('title')}}" required> <input type="text" id="title" name="title" value="{{old('title')}}" required>
@error('device_id') @error('title')
<p>{{$message}}</p> <p>{{$message}}</p>
@enderror @enderror
<br /> <br />
<label for="device_type">device_type:</label> <label for="device_type">device_type:</label>
<input type="text" id="device_type" name="device_type" value="{{old('device_type')}}" required> <input type="text" id="device_type" name="device_type" value="{{old('device_type')}}" required>
@error('device_id') @error('device_type')
<p>{{$message}}</p> <p>{{$message}}</p>
@enderror @enderror
<br /> <br />
<label for="accessories">accessories:</label> <label for="accessories">accessories:</label>
<input type="text" id="accessories" name="accessories" value="{{old('accessories')}}"> <input type="text" id="accessories" name="accessories" value="{{old('accessories')}}">
@error('device_id') @error('accessories')
<p>{{$message}}</p> <p>{{$message}}</p>
@enderror @enderror
<br /> <br />
<label for="rz_username_buyer">rz_username_buyer:</label> <label for="rz_username_buyer">rz_username_buyer:</label>
<input type="text" id="rz_username_buyer" name="rz_username_buyer" value="{{old('rz_username_buyer')}}" required> <input type="text" id="rz_username_buyer" name="rz_username_buyer" value="{{old('rz_username_buyer')}}" required>
@error('device_id') @error('rz_username_buyer')
<p>{{$message}}</p> <p>{{$message}}</p>
@enderror @enderror
<br /> <br />
<label for="serial_number">serial_number:</label> <label for="serial_number">serial_number:</label>
<input type="text" id="serial_number" name="serial_number" value="{{old('serial_number')}}" required> <input type="text" id="serial_number" name="serial_number" value="{{old('serial_number')}}" required>
@error('device_id') @error('serial_number')
<p>{{$message}}</p> <p>{{$message}}</p>
@enderror @enderror
<br /> <br />
<label for="image_url">image_url:</label> <label for="image_url">image_url:</label>
<input id="image_url" name="image_url" value="{{old('image_url')}}" required> <input id="image_url" name="image_url" value="{{old('image_url')}}" required>
@error('device_id') @error('image_url')
<p>{{$message}}</p> <p>{{$message}}</p>
@enderror @enderror
<br /> <br />
<label for="description">description:</label> <label for="description">description:</label>
<textarea type="text" id="description" name="description">{{old('rz_username_buyer')}}</textarea> <textarea type="text" id="description" name="description">{{old('rz_username_buyer')}}</textarea>
@error('device_id') @error('description')
<p>{{$message}}</p> <p>{{$message}}</p>
@enderror @enderror
<br /> <br />

View File

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

View File

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

View File

@ -1,22 +1,5 @@
@extends('layout') @extends('layout')
@section('content') @section('content')
<h1>Device Detail</h1> <x-device-detail :device="$device" />
<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>
<button><a href="{{$device->device_id}}/edit">Edit</a></button>
<form method="POST" action="{{$device->device_id}}">
@method('DELETE')
@csrf
<button>Delete</button>
</form>
@endsection @endsection

View File

@ -0,0 +1,17 @@
<form method="POST" action="/devices/{{ $device->device_id }}/locations">
@csrf
<label for="room_code">room_code:</label>
<input type="text" id="room_code" name="room_code" value="{{old('room_code')}}" required>
@error('room_code')
<p>{{ $message }}</p>
@enderror
<br />
<label for="timestamp_located_since">timestamp_located_since:</label>
<input type="text" id="timestamp_located_since" name="timestamp_located_since"
value="{{old('timestamp_located_since')}}" required>
@error('timestamp_located_since')
<p>{{ $message }}</p>
@enderror
<br />
<input type="submit" value="Submit">
</form>

View File

@ -0,0 +1,18 @@
<form method="POST" action="/devices/locations/{{ $location->location_transaction_id }}">
@method('PUT')
@csrf
<label for="room_code">room_code:</label>
<input type="text" id="room_code" name="room_code" value="{{$location->room_code}}" required>
@error('room_code')
<p>{{ $message }}</p>
@enderror
<br />
<label for="timestamp_located_since">timestamp_located_since:</label>
<input type="text" id="timestamp_located_since" name="timestamp_located_since"
value="{{$location->timestamp_located_since}}" required>
@error('timestamp_located_since')
<p>{{ $message }}</p>
@enderror
<br />
<input type="submit" value="Submit">
</form>

View File

@ -0,0 +1,17 @@
<form method="POST" action="/devices/{{ $device->device_id }}/owners">
@csrf
<label for="rz_username">rz_username:</label>
<input type="text" id="rz_username" name="rz_username" value="{{old('rz_username')}}" required>
@error('rz_username')
<p>{{ $message }}</p>
@enderror
<br />
<label for="timestamp_owner_since">timestamp_owner_since:</label>
<input type="text" id="timestamp_owner_since" name="timestamp_owner_since"
value="{{old('timestamp_owner_since')}}" required>
@error('timestamp_owner_since')
<p>{{ $message }}</p>
@enderror
<br />
<input type="submit" value="Submit">
</form>

View File

@ -0,0 +1,18 @@
<form method="POST" action="/devices/owners/{{ $owner->owner_transaction_id }}">
@method('PUT')
@csrf
<label for="rz_username">rz_username:</label>
<input type="text" id="rz_username" name="rz_username" value="{{$owner->rz_username}}" required>
@error('rz_username')
<p>{{ $message }}</p>
@enderror
<br />
<label for="timestamp_owner_since">timestamp_owner_since:</label>
<input type="text" id="timestamp_owner_since" name="timestamp_owner_since"
value="{{$owner->timestamp_owner_since}}" required>
@error('timestamp_owner_since')
<p>{{ $message }}</p>
@enderror
<br />
<input type="submit" value="Submit">
</form>

View File

@ -0,0 +1,36 @@
<form method="POST" action="/devices/{{ $purchasing->device->device_id }}/purchasing">
@method('PUT')
@csrf
<label for="price">price:</label>
<input type="text" id="price" name="price" value="{{$purchasing->price}}" required>
@error('price')
<p>{{ $message }}</p>
@enderror
<br />
<label for="timestamp_warranty_end">timestamp_warranty_end:</label>
<input type="text" id="timestamp_warranty_end" name="timestamp_warranty_end"
value="{{$purchasing->timestamp_warranty_end}}" required>
@error('timestamp_warranty_end')
<p>{{ $message }}</p>
@enderror
<br />
<label for="timestamp_purchase">timestamp_purchase:</label>
<input type="text" id="timestamp_purchase" name="timestamp_purchase"
value="{{$purchasing->timestamp_purchase}}" required>
@error('timestamp_purchase')
<p>{{ $message }}</p>
@enderror
<br />
<label for="cost_centre">cost_centre:</label>
<input type="text" id="cost_centre" name="cost_centre" value="{{$purchasing->cost_centre}}" required>
@error('cost_centre')
<p>{{ $message }}</p>
@enderror
<br />
<label for="seller">seller:</label>
<input type="text" id="seller" name="seller" value="{{$purchasing->seller}}">
@error('seller')
<p>{{ $message }}</p>
@enderror
<input type="submit" value="Submit">
</form>

View File

@ -1,6 +1,9 @@
<?php <?php
use App\Http\Controllers\DeviceController; use App\Http\Controllers\DeviceController;
use App\Http\Controllers\LocationTransactionController;
use App\Http\Controllers\OwnerTransactionController;
use App\Http\Controllers\PurchasingInformationController;
use App\Http\Controllers\UserController; use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
@ -15,16 +18,43 @@
| |
*/ */
Route::get('/', function () {
return redirect('/home');
});
Route::get('/home', function () { Route::get('/home', function () {
return view('welcome'); return view('welcome');
}); });
// Devices routes
// index - show all devices // index - show all devices
Route::get('/devices', [DeviceController::class, 'index']); Route::get('/devices', [DeviceController::class, 'index']);
// create - show device create form // create - show device create form
Route::get('/devices/create', [DeviceController::class, 'create'])->middleware('auth'); Route::get('/devices/create', [DeviceController::class, 'create'])->middleware('auth');
// store - store new device // store - store new device
Route::post('/devices', [DeviceController::class, 'store'])->middleware('auth'); Route::post('/devices', [DeviceController::class, 'store'])->middleware('auth');
// Device purchasing routes
//Route::get('/devices/{device}/purchasing/create', [PurchasingInformationController::class, 'create']);
//Route::post('/devices/{device}/purchasing', [PurchasingInformationController::class, 'store']);
Route::get('/devices/{device}/purchasing/edit', [PurchasingInformationController::class, 'edit']);
Route::put('/devices/{device}/purchasing', [PurchasingInformationController::class, 'update']);
//Route::delete('/devices/{device}/purchasing', [PurchasingInformationController::class, 'destroy']);
// Device location routes
Route::get('/devices/{device}/locations/create', [LocationTransactionController::class, 'create']);
Route::post('/devices/{device}/locations', [LocationTransactionController::class, 'store']);
Route::get('/devices/locations/{location}/edit', [LocationTransactionController::class, 'edit']);
Route::put('/devices/locations/{location}', [LocationTransactionController::class, 'update']);
Route::delete('/devices/locations/{location}', [LocationTransactionController::class, 'destroy']);
// Device owner routes
Route::get('/devices/{device}/owners/create', [OwnerTransactionController::class, 'create']);
Route::post('/devices/{device}/owners', [OwnerTransactionController::class, 'store']);
Route::get('/devices/owners/{owner}/edit', [OwnerTransactionController::class, 'edit']);
Route::put('/devices/owners/{owner}', [OwnerTransactionController::class, 'update']);
Route::delete('/devices/owners/{owner}', [OwnerTransactionController::class, 'destroy']);
//
// edit - show edit form // edit - show edit form
Route::get('devices/{device}/edit', [DeviceController::class, 'edit'])->middleware('auth'); Route::get('devices/{device}/edit', [DeviceController::class, 'edit'])->middleware('auth');
// update - update device // update - update device
@ -34,6 +64,7 @@
// show - show sigle device // show - show sigle device
Route::get('/devices/{device}', [DeviceController::class, 'show']); Route::get('/devices/{device}', [DeviceController::class, 'show']);
//User routes
// create - show register form // create - show register form
Route::get('/register', [UserController::class, 'create']); Route::get('/register', [UserController::class, 'create']);
// store - store new user // store - store new user