From 5df9e492ff80eef6f05f2016d42ac2888cccce60 Mon Sep 17 00:00:00 2001 From: TimmensOne Date: Sat, 25 Mar 2023 11:02:47 +0100 Subject: [PATCH] add device controller --- .../app/Http/Controllers/DeviceController.php | 24 +++++++++++++++++++ .../views/components/device-card.blade.php | 4 ++++ .../index.blade.php} | 6 ++--- .../show.blade.php} | 2 +- device-app/routes/web.php | 14 +++-------- 5 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 device-app/app/Http/Controllers/DeviceController.php create mode 100644 device-app/resources/views/components/device-card.blade.php rename device-app/resources/views/{deviceList.blade.php => devices/index.blade.php} (63%) rename device-app/resources/views/{deviceDetail.blade.php => devices/show.blade.php} (97%) diff --git a/device-app/app/Http/Controllers/DeviceController.php b/device-app/app/Http/Controllers/DeviceController.php new file mode 100644 index 0000000..9c01feb --- /dev/null +++ b/device-app/app/Http/Controllers/DeviceController.php @@ -0,0 +1,24 @@ + Device::all() + ]); + } + + public function show(Device $device) + { + return view('devices.show', [ + 'device' => $device + ]); + } +} diff --git a/device-app/resources/views/components/device-card.blade.php b/device-app/resources/views/components/device-card.blade.php new file mode 100644 index 0000000..dd691d8 --- /dev/null +++ b/device-app/resources/views/components/device-card.blade.php @@ -0,0 +1,4 @@ +@props(['device']) +
+ {{ $device->title }} +
\ No newline at end of file diff --git a/device-app/resources/views/deviceList.blade.php b/device-app/resources/views/devices/index.blade.php similarity index 63% rename from device-app/resources/views/deviceList.blade.php rename to device-app/resources/views/devices/index.blade.php index ab48492..0f076b0 100644 --- a/device-app/resources/views/deviceList.blade.php +++ b/device-app/resources/views/devices/index.blade.php @@ -5,12 +5,10 @@ @unless(count($devices) == 0) @else

No devices found

@endunless -@endsection \ No newline at end of file +@endsection diff --git a/device-app/resources/views/deviceDetail.blade.php b/device-app/resources/views/devices/show.blade.php similarity index 97% rename from device-app/resources/views/deviceDetail.blade.php rename to device-app/resources/views/devices/show.blade.php index 5543fca..dc468cd 100644 --- a/device-app/resources/views/deviceDetail.blade.php +++ b/device-app/resources/views/devices/show.blade.php @@ -12,4 +12,4 @@
  • {{ $device['serial_number'] }}
  • {{ $device['image_url'] }}
  • -@endsection \ No newline at end of file +@endsection diff --git a/device-app/routes/web.php b/device-app/routes/web.php index fda47db..716a9fa 100644 --- a/device-app/routes/web.php +++ b/device-app/routes/web.php @@ -1,5 +1,6 @@ Device::all() - ]); -}); +Route::get('/devices', [DeviceController::class, 'index']); -Route::get('/devices/{device_id}', function ($device_id) { - return view('deviceDetail', [ - 'device' => Device::find($device_id) - ]); -}); +Route::get('/devices/{device}', [DeviceController::class, 'show']);