38 lines
1.1 KiB
PHP
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,
|
|
]);
|
|
}
|
|
}
|
|
|