Реализация смены статуса

Добавлен move метод
Правка в поиске
This commit is contained in:
brusnitsyn
2025-12-07 22:33:19 +09:00
parent 2e1b5a3d0e
commit 945b53c578
10 changed files with 142 additions and 17 deletions

View File

@@ -2,8 +2,10 @@
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
{
@@ -18,4 +20,34 @@ class ArchiveHistoryController extends Controller
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));
}
}