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