exists) { $this->provider = $provider; $this->name = $provider->name; $this->phone = $provider->phone ?? ''; $this->email = $provider->email ?? ''; $this->website = $provider->website ?? ''; $this->notes = $provider->notes ?? ''; } } public function save(): void { $validated = $this->validate([ 'name' => 'required|string|max:255', 'phone' => 'nullable|string|max:50', 'email' => 'nullable|email|max:255', 'website' => 'nullable|string|max:255', 'notes' => 'nullable|string', 'logo' => 'nullable|image|max:2048', ]); unset($validated['logo']); foreach (['phone', 'email', 'website', 'notes'] as $field) { $validated[$field] = $validated[$field] !== '' ? $validated[$field] : null; } if ($this->provider?->exists) { $this->provider->update($validated); } else { $this->provider = Provider::create($validated); } if ($this->logo) { if ($this->provider->logo_path) { Storage::disk('public')->delete($this->provider->logo_path); } $path = $this->logo->store("providers/{$this->provider->id}", 'public'); $this->provider->update(['logo_path' => $path]); } session()->flash('status', "Prestataire « {$this->provider->name} » enregistré."); $this->redirectRoute('providers.index', navigate: true); } public function addLogEntry(): void { $this->validate([ 'newLogCategory' => 'required|in:'.implode(',', array_keys(ProviderLogEntry::CATEGORIES)), 'newLogNote' => 'required|string', ]); $this->provider->logEntries()->create([ 'category' => $this->newLogCategory, 'note' => $this->newLogNote, 'created_by' => auth()->id(), ]); $this->newLogNote = ''; } public function deleteLogEntry(int $entryId): void { $this->provider->logEntries()->findOrFail($entryId)->delete(); } public function with(): array { return [ 'logEntries' => $this->provider?->exists ? $this->provider->logEntries()->with('creator')->limit(30)->get() : collect(), 'categories' => ProviderLogEntry::CATEGORIES, ]; } }; ?>
{{ $entry->note }}
{{ $entry->creator?->name ?? 'système' }} · {{ $entry->created_at->diffForHumans() }}
Aucune entrée dans le journal pour le moment.
@endforelse