63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Device;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\LocationTransaction;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
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);
|
|
|
|
Log::info('Location saved successfully');
|
|
|
|
return redirect('/');
|
|
}
|
|
|
|
public function edit(LocationTransaction $location)
|
|
{
|
|
$this->authorize('admin-only');
|
|
return view('locations.edit', ['location' => $location]);
|
|
}
|
|
|
|
public function update(LocationTransaction $location, Request $request)
|
|
{
|
|
$this->authorize('admin-only');
|
|
$formFields = $request->validate([
|
|
'room_code' => 'required',
|
|
'timestamp_located_since' => 'required'
|
|
]);
|
|
|
|
$location->update($formFields);
|
|
|
|
Log::info('Location updated successfully');
|
|
|
|
return redirect('/');
|
|
}
|
|
|
|
public function destroy(LocationTransaction $location)
|
|
{
|
|
$this->authorize('admin-only');
|
|
$location->delete();
|
|
|
|
Log::info('Location deleted successfully');
|
|
|
|
return back();
|
|
}
|
|
}
|