Files
kartoteka/app/Http/Controllers/ArchiveHistoryController.php
brusnitsyn 945b53c578 Реализация смены статуса
Добавлен move метод
Правка в поиске
2025-12-07 22:33:19 +09:00

54 lines
1.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Resources\ArchiveHistoryResource;
use App\Models\ArchiveHistory;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
class ArchiveHistoryController extends Controller
{
public function index()
{
}
public function show($id, Request $request)
{
$archiveHistory = ArchiveHistory::find($id);
return response()->json($archiveHistory);
}
public function move(Request $request)
{
$data = $request->validate([
'issue_at' => 'nullable|numeric:',
'return_at' => 'nullable|numeric:',
'org_id' => 'required|numeric',
'employee_name' => 'nullable|string',
'employee_post' => 'nullable|string',
'comment' => 'nullable|string',
'has_lost' => 'boolean',
'historyable_id' => 'nullable|numeric',
]);
// Находим связанную модель ??
$historyable = SttMedicalHistory::findOrFail($data['historyable_id']);
// Преобразуем timestamp в дату, если пришли числа
if (isset($data['issue_at']) && is_numeric($data['issue_at'])) {
$data['issue_at'] = Carbon::createFromTimestampMs($data['issue_at'])->format('Y-m-d');
}
if (isset($data['return_at']) && is_numeric($data['return_at'])) {
$data['return_at'] = Carbon::createFromTimestampMs($data['return_at'])->format('Y-m-d');
}
$archiveHistory = ArchiveHistory::create($data);
return response()->json(ArchiveHistoryResource::make($archiveHistory));
}
}