KSA-ORACLE-ALLACCESSKEYS/app/Http/Controllers/CardImportController.php
Nyavokevin 9e5cc5ab1a
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
add dark theme
2025-09-18 20:34:07 +03:00

38 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use App\Support\CardCsvImporter;
class CardImportController extends Controller
{
public function store(Request $request)
{
$validated = $request->validate([
'csv' => 'required|file|mimetypes:text/plain,text/csv,application/vnd.ms-excel,application/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'delimiter' => 'nullable|string|in:;,|,',
'dry_run' => 'nullable|boolean',
]);
$delimiter = $request->input('delimiter', ',');
$dryRun = $request->boolean('dry_run', false);
$path = $request->file('csv')->store('imports');
$fullPath = Storage::path($path);
$importer = new CardCsvImporter();
[$inserted, $updated, $skipped] = $importer->import($fullPath, $delimiter, $dryRun);
return response()->json([
'inserted' => $inserted,
'updated' => $updated,
'skipped' => $skipped,
'dry_run' => $dryRun,
'path' => $path,
]);
}
}