add device controller
This commit is contained in:
parent
665916d05f
commit
5df9e492ff
24
device-app/app/Http/Controllers/DeviceController.php
Normal file
24
device-app/app/Http/Controllers/DeviceController.php
Normal 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
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
@props(['device'])
|
||||
<div>
|
||||
<a href="/devices/{{ $device['device_id'] }}">{{ $device->title }}</a>
|
||||
</div>
|
@ -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
|
@ -12,4 +12,4 @@
|
||||
<li>{{ $device['serial_number'] }}</li>
|
||||
<li>{{ $device['image_url'] }}</li>
|
||||
</ul>
|
||||
@endsection
|
||||
@endsection
|
@ -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']);
|
||||
|
Loading…
Reference in New Issue
Block a user