From 73ba1c8fed470bf84bd6eb66d9de7e71929e74a5 Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Fri, 31 Mar 2023 12:14:57 +0200 Subject: [PATCH] add create/edit functionality --- .../LocationTransactionController.php | 10 ++++++---- .../Controllers/OwnerTransactionController.php | 10 ++++++---- .../views/components/device-detail.blade.php | 4 ++-- .../resources/views/locations/create.blade.php | 17 +++++++++++++++++ .../resources/views/locations/edit.blade.php | 18 ++++++++++++++++++ .../resources/views/owners/create.blade.php | 17 +++++++++++++++++ .../resources/views/owners/edit.blade.php | 18 ++++++++++++++++++ .../resources/views/purchasings/edit.blade.php | 1 - 8 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 device-app/resources/views/locations/create.blade.php create mode 100644 device-app/resources/views/locations/edit.blade.php create mode 100644 device-app/resources/views/owners/create.blade.php create mode 100644 device-app/resources/views/owners/edit.blade.php diff --git a/device-app/app/Http/Controllers/LocationTransactionController.php b/device-app/app/Http/Controllers/LocationTransactionController.php index 4d23029..b40be93 100644 --- a/device-app/app/Http/Controllers/LocationTransactionController.php +++ b/device-app/app/Http/Controllers/LocationTransactionController.php @@ -2,23 +2,25 @@ namespace App\Http\Controllers; +use App\Models\Device; use Illuminate\Http\Request; use App\Models\LocationTransaction; class LocationTransactionController extends Controller { - public function create() + public function create(Device $device) { - return view('locations.create'); + return view('locations.create', ['device' => $device]); } - public function store(Request $request) + 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('/'); @@ -38,7 +40,7 @@ public function update(LocationTransaction $location, Request $request) $location->update($formFields); - return back(); + return redirect('/'); } public function destroy(LocationTransaction $location) diff --git a/device-app/app/Http/Controllers/OwnerTransactionController.php b/device-app/app/Http/Controllers/OwnerTransactionController.php index d660a21..60198fa 100644 --- a/device-app/app/Http/Controllers/OwnerTransactionController.php +++ b/device-app/app/Http/Controllers/OwnerTransactionController.php @@ -2,23 +2,25 @@ namespace App\Http\Controllers; +use App\Models\Device; use App\Models\OwnerTransaction; use Illuminate\Http\Request; class OwnerTransactionController extends Controller { - public function create() + public function create(Device $device) { - return view('owners.create'); + return view('owners.create', ['device' => $device]); } - public function store(Request $request) + 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('/'); @@ -38,7 +40,7 @@ public function update(OwnerTransaction $owner, Request $request) $owner->update($formFields); - return back(); + return redirect('/'); } public function destroy(OwnerTransaction $owner) diff --git a/device-app/resources/views/components/device-detail.blade.php b/device-app/resources/views/components/device-detail.blade.php index c449aee..7049f8f 100644 --- a/device-app/resources/views/components/device-detail.blade.php +++ b/device-app/resources/views/components/device-detail.blade.php @@ -23,12 +23,12 @@ $ownerTransactins = $device->owners; @endphp

Location Transactions

- + @foreach ($locationTransactions as $location) @endforeach

Owner Transactions

- + @foreach ($ownerTransactins as $owner) @endforeach diff --git a/device-app/resources/views/locations/create.blade.php b/device-app/resources/views/locations/create.blade.php new file mode 100644 index 0000000..4ec2798 --- /dev/null +++ b/device-app/resources/views/locations/create.blade.php @@ -0,0 +1,17 @@ +
+ @csrf + + + @error('room_code') +

{{ $message }}

+ @enderror +
+ + + @error('timestamp_located_since') +

{{ $message }}

+ @enderror +
+ +
\ No newline at end of file diff --git a/device-app/resources/views/locations/edit.blade.php b/device-app/resources/views/locations/edit.blade.php new file mode 100644 index 0000000..670475e --- /dev/null +++ b/device-app/resources/views/locations/edit.blade.php @@ -0,0 +1,18 @@ +
+ @method('PUT') + @csrf + + + @error('room_code') +

{{ $message }}

+ @enderror +
+ + + @error('timestamp_located_since') +

{{ $message }}

+ @enderror +
+ +
\ No newline at end of file diff --git a/device-app/resources/views/owners/create.blade.php b/device-app/resources/views/owners/create.blade.php new file mode 100644 index 0000000..0983a38 --- /dev/null +++ b/device-app/resources/views/owners/create.blade.php @@ -0,0 +1,17 @@ +
+ @csrf + + + @error('rz_username') +

{{ $message }}

+ @enderror +
+ + + @error('timestamp_owner_since') +

{{ $message }}

+ @enderror +
+ +
\ No newline at end of file diff --git a/device-app/resources/views/owners/edit.blade.php b/device-app/resources/views/owners/edit.blade.php new file mode 100644 index 0000000..ea8da54 --- /dev/null +++ b/device-app/resources/views/owners/edit.blade.php @@ -0,0 +1,18 @@ +
+ @method('PUT') + @csrf + + + @error('rz_username') +

{{ $message }}

+ @enderror +
+ + + @error('timestamp_owner_since') +

{{ $message }}

+ @enderror +
+ +
\ No newline at end of file diff --git a/device-app/resources/views/purchasings/edit.blade.php b/device-app/resources/views/purchasings/edit.blade.php index 762a3af..db0791c 100644 --- a/device-app/resources/views/purchasings/edit.blade.php +++ b/device-app/resources/views/purchasings/edit.blade.php @@ -1,4 +1,3 @@ -

{{ $purchasing->price }}

@method('PUT') @csrf