Commit f98f2b2b authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix participant import: rename $errors to $importErrors to avoid Livewire conflict

Livewire reserves $errors for the validation MessageBag. Using the same
name as a public property causes a 500 error on render.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent aecd624c
...@@ -20,7 +20,7 @@ class ParticipantImport extends Component ...@@ -20,7 +20,7 @@ class ParticipantImport extends Component
public $file; public $file;
public array $preview = []; public array $preview = [];
public array $errors = []; public array $importErrors = [];
public int $imported = 0; public int $imported = 0;
public int $skipped = 0; public int $skipped = 0;
public bool $processing = false; public bool $processing = false;
...@@ -42,14 +42,14 @@ public function updatedFile(): void ...@@ -42,14 +42,14 @@ public function updatedFile(): void
{ {
$this->validate(); $this->validate();
$this->preview = []; $this->preview = [];
$this->errors = []; $this->importErrors = [];
$path = $this->file->getRealPath(); $path = $this->file->getRealPath();
$handle = fopen($path, 'r'); $handle = fopen($path, 'r');
$header = fgetcsv($handle); $header = fgetcsv($handle);
if (!$header) { if (!$header) {
$this->errors[] = 'الملف فارغ أو غير صالح'; $this->importErrors[] = 'الملف فارغ أو غير صالح';
fclose($handle); fclose($handle);
return; return;
} }
...@@ -58,7 +58,7 @@ public function updatedFile(): void ...@@ -58,7 +58,7 @@ public function updatedFile(): void
$required = ['name_ar', 'phone']; $required = ['name_ar', 'phone'];
$missing = array_diff($required, $header); $missing = array_diff($required, $header);
if (!empty($missing)) { if (!empty($missing)) {
$this->errors[] = 'أعمدة مفقودة: ' . implode(', ', $missing); $this->importErrors[] = 'أعمدة مفقودة: ' . implode(', ', $missing);
fclose($handle); fclose($handle);
return; return;
} }
...@@ -79,7 +79,7 @@ public function import(): void ...@@ -79,7 +79,7 @@ public function import(): void
$this->processing = true; $this->processing = true;
$this->imported = 0; $this->imported = 0;
$this->skipped = 0; $this->skipped = 0;
$this->errors = []; $this->importErrors = [];
$branchId = $this->getActiveBranchIdOrFail(); $branchId = $this->getActiveBranchIdOrFail();
$path = $this->file->getRealPath(); $path = $this->file->getRealPath();
...@@ -93,7 +93,7 @@ public function import(): void ...@@ -93,7 +93,7 @@ public function import(): void
while (($row = fgetcsv($handle)) !== false) { while (($row = fgetcsv($handle)) !== false) {
$lineNum++; $lineNum++;
if (count($row) !== count($header)) { if (count($row) !== count($header)) {
$this->errors[] = "سطر {$lineNum}: عدد الأعمدة غير متطابق"; $this->importErrors[] = "سطر {$lineNum}: عدد الأعمدة غير متطابق";
$this->skipped++; $this->skipped++;
continue; continue;
} }
...@@ -106,7 +106,7 @@ public function import(): void ...@@ -106,7 +106,7 @@ public function import(): void
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
$this->errors[] = "سطر {$lineNum}: " . implode(', ', $validator->errors()->all()); $this->importErrors[] = "سطر {$lineNum}: " . implode(', ', $validator->errors()->all());
$this->skipped++; $this->skipped++;
continue; continue;
} }
...@@ -148,7 +148,7 @@ public function import(): void ...@@ -148,7 +148,7 @@ public function import(): void
DB::commit(); DB::commit();
} catch (\Throwable $e) { } catch (\Throwable $e) {
DB::rollBack(); DB::rollBack();
$this->errors[] = 'خطأ: ' . $e->getMessage(); $this->importErrors[] = 'خطأ: ' . $e->getMessage();
} }
fclose($handle); fclose($handle);
......
...@@ -62,11 +62,11 @@ class="mt-4 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabl ...@@ -62,11 +62,11 @@ class="mt-4 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabl
@endif @endif
{{-- Errors --}} {{-- Errors --}}
@if(!empty($errors)) @if(!empty($importErrors))
<div class="bg-red-50 border border-red-200 rounded-xl p-4 mb-6"> <div class="bg-red-50 border border-red-200 rounded-xl p-4 mb-6">
<h3 class="text-sm font-semibold text-red-800 mb-2">{{ __('أخطاء') }}</h3> <h3 class="text-sm font-semibold text-red-800 mb-2">{{ __('أخطاء') }}</h3>
<ul class="text-sm text-red-700 space-y-1 max-h-40 overflow-y-auto"> <ul class="text-sm text-red-700 space-y-1 max-h-40 overflow-y-auto">
@foreach($errors as $error) @foreach($importErrors as $error)
<li>{{ $error }}</li> <li>{{ $error }}</li>
@endforeach @endforeach
</ul> </ul>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment