2023-03-31 10:52:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2023-03-31 12:14:57 +02:00
|
|
|
use App\Models\Device;
|
2023-03-31 10:52:12 +02:00
|
|
|
use App\Models\OwnerTransaction;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class OwnerTransactionController extends Controller
|
|
|
|
{
|
2023-03-31 12:14:57 +02:00
|
|
|
public function create(Device $device)
|
2023-03-31 10:52:12 +02:00
|
|
|
{
|
2023-03-31 12:14:57 +02:00
|
|
|
return view('owners.create', ['device' => $device]);
|
2023-03-31 10:52:12 +02:00
|
|
|
}
|
|
|
|
|
2023-03-31 12:14:57 +02:00
|
|
|
public function store(Device $device, Request $request)
|
2023-03-31 10:52:12 +02:00
|
|
|
{
|
|
|
|
$formFields = $request->validate([
|
|
|
|
'rz_username' => 'required',
|
|
|
|
'timestamp_owner_since' => 'required'
|
|
|
|
]);
|
|
|
|
|
2023-03-31 12:14:57 +02:00
|
|
|
$formFields['device_id'] = $device->device_id;
|
2023-03-31 10:52:12 +02:00
|
|
|
OwnerTransaction::create($formFields);
|
|
|
|
|
|
|
|
return redirect('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function edit(OwnerTransaction $owner)
|
|
|
|
{
|
2023-03-31 17:17:09 +02:00
|
|
|
$this->authorize('admin-only');
|
2023-03-31 10:52:12 +02:00
|
|
|
return view('owners.edit', ['owner' => $owner]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(OwnerTransaction $owner, Request $request)
|
|
|
|
{
|
2023-03-31 17:17:09 +02:00
|
|
|
$this->authorize('admin-only');
|
2023-03-31 10:52:12 +02:00
|
|
|
$formFields = $request->validate([
|
|
|
|
'rz_username' => 'required',
|
|
|
|
'timestamp_owner_since' => 'required'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$owner->update($formFields);
|
|
|
|
|
2023-03-31 12:14:57 +02:00
|
|
|
return redirect('/');
|
2023-03-31 10:52:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(OwnerTransaction $owner)
|
|
|
|
{
|
2023-03-31 17:17:09 +02:00
|
|
|
$this->authorize('admin-only');
|
2023-03-31 10:52:12 +02:00
|
|
|
$owner->delete();
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
}
|