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
public $file;
public array $preview = [];
public array $errors = [];
public array $importErrors = [];
public int $imported = 0;
public int $skipped = 0;
public bool $processing = false;
......@@ -42,14 +42,14 @@ public function updatedFile(): void
{
$this->validate();
$this->preview = [];
$this->errors = [];
$this->importErrors = [];
$path = $this->file->getRealPath();
$handle = fopen($path, 'r');
$header = fgetcsv($handle);
if (!$header) {
$this->errors[] = 'الملف فارغ أو غير صالح';
$this->importErrors[] = 'الملف فارغ أو غير صالح';
fclose($handle);
return;
}
......@@ -58,7 +58,7 @@ public function updatedFile(): void
$required = ['name_ar', 'phone'];
$missing = array_diff($required, $header);
if (!empty($missing)) {
$this->errors[] = 'أعمدة مفقودة: ' . implode(', ', $missing);
$this->importErrors[] = 'أعمدة مفقودة: ' . implode(', ', $missing);
fclose($handle);
return;
}
......@@ -79,7 +79,7 @@ public function import(): void
$this->processing = true;
$this->imported = 0;
$this->skipped = 0;
$this->errors = [];
$this->importErrors = [];
$branchId = $this->getActiveBranchIdOrFail();
$path = $this->file->getRealPath();
......@@ -93,7 +93,7 @@ public function import(): void
while (($row = fgetcsv($handle)) !== false) {
$lineNum++;
if (count($row) !== count($header)) {
$this->errors[] = "سطر {$lineNum}: عدد الأعمدة غير متطابق";
$this->importErrors[] = "سطر {$lineNum}: عدد الأعمدة غير متطابق";
$this->skipped++;
continue;
}
......@@ -106,7 +106,7 @@ public function import(): void
]);
if ($validator->fails()) {
$this->errors[] = "سطر {$lineNum}: " . implode(', ', $validator->errors()->all());
$this->importErrors[] = "سطر {$lineNum}: " . implode(', ', $validator->errors()->all());
$this->skipped++;
continue;
}
......@@ -148,7 +148,7 @@ public function import(): void
DB::commit();
} catch (\Throwable $e) {
DB::rollBack();
$this->errors[] = 'خطأ: ' . $e->getMessage();
$this->importErrors[] = 'خطأ: ' . $e->getMessage();
}
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
@endif
{{-- Errors --}}
@if(!empty($errors))
@if(!empty($importErrors))
<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>
<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>
@endforeach
</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