From 13f933e0b5336a214699cfd07aea87e847b0e68c Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Sun, 26 Mar 2023 18:16:26 +0200 Subject: [PATCH] add update and delete --- .../app/Http/Controllers/DeviceController.php | 22 +++++++++++++++++++ .../resources/views/devices/edit.blade.php | 4 ++-- .../resources/views/devices/show.blade.php | 6 +++++ device-app/routes/web.php | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/device-app/app/Http/Controllers/DeviceController.php b/device-app/app/Http/Controllers/DeviceController.php index 673ec71..d138133 100644 --- a/device-app/app/Http/Controllers/DeviceController.php +++ b/device-app/app/Http/Controllers/DeviceController.php @@ -41,6 +41,28 @@ public function edit(Device $device) { return view('devices.edit', ['device' => $device]); } + public function update(Device $device, Request $request){ + $formFields = $request->validate([ + 'device_id' => 'required', + 'title' => 'required', + 'device_type' => 'required', + 'description' => 'required', + 'accessories' => 'required', + 'rz_username_buyer' => 'required', + 'serial_number' => 'required', + 'image_url' => 'required', + ]); + + $device->update($formFields); + + return back(); + } + + public function destroy(Device $device){ + $device->delete(); + return redirect('devices'); + } + public function show(Device $device) { return view('devices.show', [ diff --git a/device-app/resources/views/devices/edit.blade.php b/device-app/resources/views/devices/edit.blade.php index 0acce54..073da5a 100644 --- a/device-app/resources/views/devices/edit.blade.php +++ b/device-app/resources/views/devices/edit.blade.php @@ -2,8 +2,8 @@ @section('content')
- @csrf @method('PUT') + @csrf @error('device_id') @@ -47,7 +47,7 @@ @enderror
- + @error('device_id')

{{$message}}

@enderror diff --git a/device-app/resources/views/devices/show.blade.php b/device-app/resources/views/devices/show.blade.php index b6713fe..e3958e2 100644 --- a/device-app/resources/views/devices/show.blade.php +++ b/device-app/resources/views/devices/show.blade.php @@ -13,4 +13,10 @@
  • {{ $device['image_url'] }}
  • + + + @method('DELETE') + @csrf + +
    @endsection diff --git a/device-app/routes/web.php b/device-app/routes/web.php index 471f73f..1d564ad 100644 --- a/device-app/routes/web.php +++ b/device-app/routes/web.php @@ -32,6 +32,10 @@ Route::get('devices/{device}/edit', [DeviceController::class, 'edit']); // update - update device +Route::put('devices/{device}', [DeviceController::class, 'update']); + // destroy - delete device +Route::delete('devices/{device}', [DeviceController::class, 'destroy']); + // show - show sigle device Route::get('/devices/{device}', [DeviceController::class, 'show']);