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,9 +5,7 @@
@unless(count($devices) == 0) @unless(count($devices) == 0)
<ul> <ul>
@foreach ($devices as $device) @foreach ($devices as $device)
<li> <x-device-card :device="$device" />
<a href="/devices/{{ $device['device_id'] }}">{{ $device->title }}</a>
</li>
@endforeach @endforeach
</ul> </ul>
@else @else

View File

@ -1,5 +1,6 @@
<?php <?php
use App\Http\Controllers\DeviceController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use App\Models\Device; use App\Models\Device;
@ -18,15 +19,6 @@
return view('welcome'); return view('welcome');
}); });
Route::get('/devices', function () { Route::get('/devices', [DeviceController::class, 'index']);
//return view('deviceList');
return view('deviceList', [
'devices' => Device::all()
]);
});
Route::get('/devices/{device_id}', function ($device_id) { Route::get('/devices/{device}', [DeviceController::class, 'show']);
return view('deviceDetail', [
'device' => Device::find($device_id)
]);
});