client = $client; $this->company_name = $client->company_name ?? ''; $this->company_cert_number = $client->company_cert_number ?? ''; $this->contact_person_name = $client->contact_person_name ?? ''; $this->contact_person_id = $client->contact_person_id ?? ''; $this->email = $client->email; $this->phone = $client->phone ?? ''; $this->preferred_language = $client->preferred_language ?? 'ar'; $this->status = $client->status->value; } public function rules(): array { return [ 'company_name' => ['required', 'string', 'max:255'], 'company_cert_number' => ['required', 'string', 'max:100', Rule::unique('users', 'company_cert_number')->ignore($this->client->id)], 'contact_person_name' => ['required', 'string', 'max:255'], 'contact_person_id' => ['required', 'string', 'max:50'], 'email' => ['required', 'email', 'max:255', Rule::unique('users', 'email')->ignore($this->client->id)], 'phone' => ['required', 'string', 'max:20'], 'password' => ['nullable', 'string', 'min:8'], 'preferred_language' => ['required', 'in:ar,en'], 'status' => ['required', 'in:active,deactivated'], ]; } public function messages(): array { return [ 'company_cert_number.unique' => __('clients.registration_number_exists'), 'email.unique' => __('clients.email_exists'), ]; } public function update(): void { $validated = $this->validate(); $oldValues = $this->client->only(['company_name', 'email', 'company_cert_number', 'contact_person_name', 'contact_person_id', 'phone', 'preferred_language', 'status']); $this->client->company_name = $validated['company_name']; $this->client->full_name = $validated['company_name']; $this->client->company_cert_number = $validated['company_cert_number']; $this->client->contact_person_name = $validated['contact_person_name']; $this->client->contact_person_id = $validated['contact_person_id']; $this->client->email = $validated['email']; $this->client->phone = $validated['phone']; $this->client->preferred_language = $validated['preferred_language']; $this->client->status = $validated['status']; if (! empty($validated['password'])) { $this->client->password = Hash::make($validated['password']); } $this->client->save(); AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'update', 'target_type' => 'user', 'target_id' => $this->client->id, 'old_values' => $oldValues, 'new_values' => $this->client->only(['company_name', 'email', 'company_cert_number', 'contact_person_name', 'contact_person_id', 'phone', 'preferred_language', 'status']), 'ip_address' => request()->ip(), 'created_at' => now(), ]); session()->flash('success', __('clients.company_updated')); $this->redirect(route('admin.clients.company.index'), navigate: true); } public function with(): array { return [ 'statuses' => UserStatus::cases(), ]; } }; ?>