validate(['newFolderName' => 'required|string|max:255']); $this->organization->documents()->create([ 'folder_id' => $this->folderId, 'name' => $this->newFolderName, 'is_folder' => true, 'created_by' => auth()->id(), ]); $this->newFolderName = ''; $this->showNewFolder = false; } public function createMarkdownDocument(): void { $document = $this->organization->documents()->create([ 'folder_id' => $this->folderId, 'name' => 'Document sans titre', 'type' => 'markdown', 'content' => '', 'created_by' => auth()->id(), ]); $document->versions()->create([ 'version' => 1, 'content' => '', 'created_by' => auth()->id(), ]); $this->redirectRoute('organizations.documents.edit', [$this->organization, $document, 'edit' => true], navigate: true); } public function createOfficeDocument(string $extension): void { abort_unless(in_array($extension, ['docx', 'xlsx'], true), 400); $name = $extension === 'xlsx' ? 'Feuille de calcul sans titre' : 'Document sans titre'; $document = $this->organization->documents()->create([ 'folder_id' => $this->folderId, 'name' => $name, 'type' => 'office', 'office_extension' => $extension, 'office_key' => Str::random(20), 'created_by' => auth()->id(), ]); $document->file_path = "documents/office/{$this->organization->id}/{$document->id}.{$extension}"; Storage::put($document->file_path, file_get_contents(resource_path("office-templates/blank.{$extension}"))); $document->save(); $document->versions()->create([ 'version' => 1, 'created_by' => auth()->id(), ]); $this->redirectRoute('organizations.documents.edit', [$this->organization, $document, 'edit' => true], navigate: true); } public function updatedUploadedFile(): void { $this->validate([ 'uploadedFile' => 'required|file|max:51200|mimes:'.implode(',', [...self::OFFICE_EXTENSIONS, ...self::UPLOAD_EXTENSIONS]), ]); $extension = strtolower($this->uploadedFile->getClientOriginalExtension()); $originalName = $this->uploadedFile->getClientOriginalName(); $isOffice = in_array($extension, self::OFFICE_EXTENSIONS, true); $document = $this->organization->documents()->create([ 'folder_id' => $this->folderId, 'name' => $originalName, 'type' => $isOffice ? 'office' : 'upload', 'office_extension' => $isOffice ? $extension : null, 'office_key' => $isOffice ? Str::random(20) : null, 'created_by' => auth()->id(), ]); $storedPath = $isOffice ? "documents/office/{$this->organization->id}/{$document->id}.{$extension}" : "documents/uploads/{$this->organization->id}/{$document->id}.{$extension}"; Storage::put($storedPath, file_get_contents($this->uploadedFile->getRealPath())); $document->update(['file_path' => $storedPath]); $document->versions()->create([ 'version' => 1, 'created_by' => auth()->id(), ]); $this->uploadedFile = null; session()->flash('status', "\"{$originalName}\" importé."); } public function delete(int $documentId): void { $document = $this->organization->documents()->findOrFail($documentId); $document->delete(); session()->flash('status', "\"{$document->name}\" supprimé."); } public function moveDocument(int $documentId, ?int $targetFolderId): void { $document = $this->organization->documents()->findOrFail($documentId); if ($document->id === $targetFolderId) { return; } if ($targetFolderId !== null) { $targetFolder = $this->organization->documents()->find($targetFolderId); if (! $targetFolder || ! $targetFolder->isFolder()) { return; } // Prevent moving a folder into itself or one of its own descendants. if ($document->isFolder()) { $walk = $targetFolder; while ($walk) { if ($walk->id === $document->id) { return; } $walk = $walk->folder; } } } if ($document->folder_id === $targetFolderId) { return; } $document->update(['folder_id' => $targetFolderId]); session()->flash('status', "\"{$document->name}\" déplacé."); } /** * All folders as a flat list ordered depth-first (parent immediately * followed by its children), each annotated with its nesting depth so * the "move to" dropdown can render indentation reflecting the tree. * * @return \Illuminate\Support\Collection */ private function folderTree(\Illuminate\Support\Collection $allFolders): \Illuminate\Support\Collection { $byParent = $allFolders->groupBy('folder_id'); $walk = function ($parentId, $depth) use (&$walk, $byParent) { return ($byParent->get($parentId) ?? collect()) ->sortBy('name') ->flatMap(fn ($folder) => collect([['folder' => $folder, 'depth' => $depth]]) ->concat($walk($folder->id, $depth + 1))); }; return $walk(null, 0); } public function with(): array { $currentFolder = $this->folderId ? $this->organization->documents()->find($this->folderId) : null; $breadcrumbs = collect(); $walk = $currentFolder; while ($walk) { $breadcrumbs->prepend($walk); $walk = $walk->folder; } $allFolders = $this->organization->documents()->where('is_folder', true)->get(); return [ 'currentFolder' => $currentFolder, 'breadcrumbs' => $breadcrumbs, 'items' => $this->organization->documents() ->where('folder_id', $this->folderId) ->where('type', '!=', 'diagram') ->orderByDesc('is_folder') ->orderBy('name') ->get(), 'folderTree' => $this->folderTree($allFolders), ]; } }; ?>

{{ $organization->name }}

Documents

📄
Import en cours...
@error('uploadedFile')
{{ $message }}
@enderror
Documents @foreach ($breadcrumbs as $crumb) / {{ $crumb->name }} @endforeach
@if ($showNewFolder)
@error('newFolderName')

{{ $message }}

@enderror
@endif @if ($items->isNotEmpty())

Astuce : glissez-déposez un élément sur un dossier pour le déplacer.

@endif
@forelse ($items as $item) @php $isFolder = $item->isFolder(); @endphp @empty @endforelse
Nom Version Mis à jour
@if ($isFolder) 📁 {{ $item->name }} @else {{ match(true) { $item->office_extension === 'xlsx' => '📊', $item->type === 'markdown' => '📝', $item->type === 'upload' => '📎', default => '📄', } }} {{ $item->name }} @endif {{ $isFolder ? '—' : 'v'.$item->current_version }} {{ $item->updated_at->diffForHumans() }} @unless ($isFolder) {{ $item->type === 'upload' ? 'Ouvrir' : 'Modifier' }} @endunless @php // Exclude the item's own subtree (if it's a folder) so it can't be moved into itself or a descendant. $excludedIds = [$item->id, $item->folder_id]; if ($isFolder) { $stack = [$item->id]; while ($stack) { $id = array_pop($stack); foreach ($folderTree as $node) { if ($node['folder']->folder_id === $id) { $excludedIds[] = $node['folder']->id; $stack[] = $node['folder']->id; } } } } $moveTargets = $folderTree->reject(fn ($node) => in_array($node['folder']->id, $excludedIds, true)); @endphp @if ($moveTargets->isNotEmpty() || $item->folder_id !== null) @endif
Dossier vide.
@if ($currentFolder)
⬆️ Glisser ici pour remonter au dossier parent
@endif