add device controller

This commit is contained in:
TimmensOne 2023-03-25 11:02:47 +01:00
parent 665916d05f
commit 5df9e492ff
5 changed files with 34 additions and 16 deletions

View File

@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers;
use App\Models\Device;
use Illuminate\Http\Request;
class DeviceController extends Controller
{
//
public function index()
{
return view('devices.index', [
'devices' => Device::all()
]);
}
public function show(Device $device)
{
return view('devices.show', [
'device' => $device
]);
}
}

View File

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

View File

@ -5,12 +5,10 @@
@unless(count($devices) == 0)
<ul>
@foreach ($devices as $device)
<li>
<a href="/devices/{{ $device['device_id'] }}">{{ $device->title }}</a>
</li>
<x-device-card :device="$device" />
@endforeach
</ul>
@else
<p>No devices found</p>
@endunless
@endsection
@endsection

View File

@ -12,4 +12,4 @@
<li>{{ $device['serial_number'] }}</li>
<li>{{ $device['image_url'] }}</li>
</ul>
@endsection
@endsection

View File

@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\DeviceController;
use Illuminate\Support\Facades\Route;
use App\Models\Device;
@ -18,15 +19,6 @@
return view('welcome');
});
Route::get('/devices', function () {
//return view('deviceList');
return view('deviceList', [
'devices' => 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']);