abschlussprojekt-device-man.../device-app/app/Http/Controllers/LocationTransactionController.php
2023-03-31 12:14:57 +02:00

52 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Device;
use Illuminate\Http\Request;
use App\Models\LocationTransaction;
class LocationTransactionController extends Controller
{
public function create(Device $device)
{
return view('locations.create', ['device' => $device]);
}
public function store(Device $device, Request $request)
{
$formFields = $request->validate([
'room_code' => 'required',
'timestamp_located_since' => 'required'
]);
$formFields['device_id'] = $device->device_id;
LocationTransaction::create($formFields);
return redirect('/');
}
public function edit(LocationTransaction $location)
{
return view('locations.edit', ['location' => $location]);
}
public function update(LocationTransaction $location, Request $request)
{
$formFields = $request->validate([
'room_code' => 'required',
'timestamp_located_since' => 'required'
]);
$location->update($formFields);
return redirect('/');
}
public function destroy(LocationTransaction $location)
{
$location->delete();
return back();
}
}