validate([ 'file' => ['required', 'file', 'mimes:pdf,jpg,jpeg,png', 'max:10240'], ]); $user = Auth::user(); if ($user->ocr_provider === 'none') { return; } $this->scanning = true; $suggestions = app(OcrManager::class) ->driver($user->ocr_provider) ->analyze($this->file->getRealPath(), $user->ocr_api_key); if (blank($this->title) && filled($suggestions['title'] ?? null)) { $this->title = $suggestions['title']; } if (blank($this->expires_at) && filled($suggestions['expires_at'] ?? null)) { $this->expires_at = $suggestions['expires_at']; } $this->scanning = false; } public function save(): void { $validated = $this->validate([ 'file' => ['required', 'file', 'mimes:pdf,jpg,jpeg,png', 'max:10240'], 'title' => ['required', 'string', 'max:255'], 'category_id' => ['nullable', 'integer', 'exists:categories,id'], 'issuer' => ['nullable', 'string', 'max:255'], 'certificate_number' => ['nullable', 'string', 'max:255'], 'issued_at' => ['nullable', 'date', 'before_or_equal:expires_at'], 'expires_at' => ['required', 'date'], 'notes' => ['nullable', 'string', 'max:2000'], ]); $path = $this->file->storeAs( 'certificates/'.Auth::id(), Str::uuid().'.'.$this->file->getClientOriginalExtension(), 'local' ); Auth::user()->certificates()->create([ 'title' => $validated['title'], 'category_id' => $validated['category_id'] ?: null, 'issuer' => $validated['issuer'] ?: null, 'certificate_number' => $validated['certificate_number'] ?: null, 'issued_at' => $validated['issued_at'] ?: null, 'file_path' => $path, 'expires_at' => $validated['expires_at'], 'notes' => $validated['notes'] ?: null, ]); Flux::toast(variant: 'success', text: __('Certificate added.')); $this->redirectRoute('certificates.index', navigate: true); } /** * @return Collection */ #[Computed] public function categories(): Collection { return Category::orderBy('name')->get(); } }; ?>
{{ __('Add certificate') }} {{ __('Upload a document to preview it, then confirm the details — pre-filled automatically if scanning is enabled.') }}
{{-- Left: live document preview (client-side, before upload completes) --}}
{{ __('Select a document to preview it here.') }}
{{ __('Uploading…') }}
{{-- Right: form fields --}}
@if ($scanning) {{ __('Scanning document for suggestions…') }} @endif {{ __('Uncategorized') }} @foreach ($this->categories as $category) {{ $category->name }} @endforeach
{{ __('Save certificate') }} {{ __('Cancel') }}