Added Documentation
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => 'Documentation',
|
||||
'route_prefix' => 'documentation',
|
||||
'middleware' => ['web', 'auth'],
|
||||
'storage_disk' => env('DOCUMENTATION_DISK', 'public'),
|
||||
'upload_path' => env('DOCUMENTATION_UPLOAD_PATH', 'documentation'),
|
||||
'allowed_upload_mimes' => [
|
||||
'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'md', 'csv', 'png', 'jpg', 'jpeg', 'webp',
|
||||
],
|
||||
'max_upload_kb' => 20480,
|
||||
'import_markdown_attachments' => true,
|
||||
'max_markdown_import_bytes' => 1048576,
|
||||
'editor' => [
|
||||
'markdown_toolbar' => true,
|
||||
'supports_code_blocks' => true,
|
||||
'supports_tables' => true,
|
||||
],
|
||||
'statuses' => [
|
||||
'draft' => 'Draft',
|
||||
'published' => 'Published',
|
||||
'archived' => 'Archived',
|
||||
],
|
||||
];
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('documentation_categories', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('name')->comment('Human-readable category name.');
|
||||
$table->string('slug')->unique()->comment('URL-safe category identifier.');
|
||||
$table->string('icon')->nullable()->comment('Optional UI icon class or key.');
|
||||
$table->string('colour', 32)->default('emerald')->comment('Display colour token.');
|
||||
$table->text('description')->nullable()->comment('Category description shown in the documentation UI.');
|
||||
$table->unsignedInteger('sort_order')->default(0)->index()->comment('Manual display order.');
|
||||
$table->boolean('is_active')->default(true)->index()->comment('Whether the category is visible and usable.');
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete()->comment('User that created the category.');
|
||||
$table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete()->comment('Last user that updated the category.');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('documentation_categories');
|
||||
}
|
||||
};
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('documentation_documents', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('documentation_category_id')->nullable()->constrained('documentation_categories')->nullOnDelete()->comment('Optional owning documentation category.');
|
||||
$table->string('title')->comment('Document title.');
|
||||
$table->string('slug')->unique()->comment('URL-safe document identifier.');
|
||||
$table->string('summary', 500)->nullable()->comment('Short document summary.');
|
||||
$table->longText('body')->nullable()->comment('Full document body, markdown or HTML-safe text depending on editor implementation.');
|
||||
$table->string('status', 32)->default('draft')->index()->comment('Workflow status: draft, published, or archived.');
|
||||
$table->boolean('is_featured')->default(false)->index()->comment('Whether this document is highlighted on the documentation dashboard.');
|
||||
$table->string('version', 50)->default('1.0.0')->comment('Document version label.');
|
||||
$table->string('reference', 100)->nullable()->index()->comment('Optional business reference or document code.');
|
||||
$table->string('attachment_disk')->nullable()->comment('Storage disk used for the attached file.');
|
||||
$table->string('attachment_path')->nullable()->comment('Storage path for the attached file.');
|
||||
$table->string('attachment_name')->nullable()->comment('Original uploaded file name.');
|
||||
$table->string('attachment_mime')->nullable()->comment('Uploaded file MIME type.');
|
||||
$table->unsignedBigInteger('attachment_size')->nullable()->comment('Uploaded file size in bytes.');
|
||||
$table->timestamp('published_at')->nullable()->index()->comment('Date/time the document was published.');
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete()->comment('User that created the document.');
|
||||
$table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete()->comment('Last user that updated the document.');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['status', 'is_featured']);
|
||||
$table->index(['documentation_category_id', 'status']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('documentation_documents');
|
||||
}
|
||||
};
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('documentation_attachments', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('documentation_document_id')->constrained('documentation_documents')->cascadeOnDelete()->comment('Owning documentation document.');
|
||||
$table->string('disk')->comment('Storage disk used for the uploaded attachment.');
|
||||
$table->string('path')->comment('Storage path for the uploaded attachment.');
|
||||
$table->string('original_name')->comment('Original uploaded file name.');
|
||||
$table->string('mime_type')->nullable()->comment('Uploaded file MIME type.');
|
||||
$table->unsignedBigInteger('size')->nullable()->comment('Uploaded file size in bytes.');
|
||||
$table->foreignId('uploaded_by')->nullable()->constrained('users')->nullOnDelete()->comment('User that uploaded the attachment.');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['documentation_document_id', 'created_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('documentation_attachments');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Http\Controllers;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Documentation\Http\Requests\StoreDocumentationCategoryRequest;
|
||||
use Modules\Documentation\Http\Requests\UpdateDocumentationCategoryRequest;
|
||||
use Modules\Documentation\Models\DocumentationCategory;
|
||||
|
||||
class DocumentationCategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display category list.
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
return view('documentation::categories.index', [
|
||||
'categories' => DocumentationCategory::query()->withCount('documents')->ordered()->paginate(15),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show create form.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('documentation::categories.create', [
|
||||
'category' => new DocumentationCategory(['colour' => 'emerald', 'is_active' => true]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a category.
|
||||
*/
|
||||
public function store(StoreDocumentationCategoryRequest $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validated();
|
||||
$data['is_active'] = $request->boolean('is_active', true);
|
||||
$data['created_by'] = $request->user()?->id;
|
||||
$data['updated_by'] = $request->user()?->id;
|
||||
|
||||
DocumentationCategory::query()->create($data);
|
||||
|
||||
return redirect()->route('documentation.categories.index')->with('status', 'Category created successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show edit form.
|
||||
*/
|
||||
public function edit(DocumentationCategory $category): View
|
||||
{
|
||||
return view('documentation::categories.edit', [
|
||||
'category' => $category,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a category.
|
||||
*/
|
||||
public function update(UpdateDocumentationCategoryRequest $request, DocumentationCategory $category): RedirectResponse
|
||||
{
|
||||
$data = $request->validated();
|
||||
$data['is_active'] = $request->boolean('is_active');
|
||||
$data['updated_by'] = $request->user()?->id;
|
||||
|
||||
$category->update($data);
|
||||
|
||||
return redirect()->route('documentation.categories.index')->with('status', 'Category updated successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a category.
|
||||
*/
|
||||
public function destroy(DocumentationCategory $category): RedirectResponse
|
||||
{
|
||||
$category->delete();
|
||||
|
||||
return redirect()->route('documentation.categories.index')->with('status', 'Category deleted successfully.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Http\Controllers;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Modules\Documentation\Http\Requests\StoreDocumentationDocumentRequest;
|
||||
use Modules\Documentation\Http\Requests\UpdateDocumentationDocumentRequest;
|
||||
use Modules\Documentation\Models\DocumentationCategory;
|
||||
use Modules\Documentation\Models\DocumentationDocument;
|
||||
use Modules\Documentation\Models\DocumentationAttachment;
|
||||
|
||||
class DocumentationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the documentation dashboard and document list.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$query = DocumentationDocument::query()->with(['category', 'attachments'])->latest();
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->string('status')->toString());
|
||||
}
|
||||
|
||||
if ($request->filled('category')) {
|
||||
$query->where('documentation_category_id', $request->integer('category'));
|
||||
}
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = '%' . $request->string('search')->trim()->toString() . '%';
|
||||
$query->where(function ($builder) use ($search): void {
|
||||
$builder->where('title', 'like', $search)
|
||||
->orWhere('summary', 'like', $search)
|
||||
->orWhere('reference', 'like', $search)
|
||||
->orWhere('body', 'like', $search);
|
||||
});
|
||||
}
|
||||
|
||||
return view('documentation::documents.index', [
|
||||
'documents' => $query->paginate(15)->withQueryString(),
|
||||
'categories' => DocumentationCategory::query()->ordered()->get(),
|
||||
'featuredDocuments' => DocumentationDocument::query()->with('category')->featured()->latest()->limit(4)->get(),
|
||||
'stats' => [
|
||||
'total' => DocumentationDocument::query()->count(),
|
||||
'published' => DocumentationDocument::query()->published()->count(),
|
||||
'drafts' => DocumentationDocument::query()->where('status', DocumentationDocument::STATUS_DRAFT)->count(),
|
||||
'categories' => DocumentationCategory::query()->count(),
|
||||
],
|
||||
'statuses' => config('documentation.statuses', []),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the create document form.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('documentation::documents.create', [
|
||||
'document' => new DocumentationDocument(['status' => DocumentationDocument::STATUS_DRAFT, 'version' => '1.0.0']),
|
||||
'categories' => DocumentationCategory::query()->active()->ordered()->get(),
|
||||
'statuses' => config('documentation.statuses', []),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created document.
|
||||
*/
|
||||
public function store(StoreDocumentationDocumentRequest $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validated();
|
||||
$data['is_featured'] = $request->boolean('is_featured');
|
||||
$data['created_by'] = $request->user()?->id;
|
||||
$data['updated_by'] = $request->user()?->id;
|
||||
|
||||
if ($request->hasFile('attachment')) {
|
||||
if (blank($data['body'] ?? null)) {
|
||||
$data['body'] = $this->extractMarkdownBody($request) ?: ($data['body'] ?? null);
|
||||
}
|
||||
|
||||
$data = array_merge($data, $this->storeAttachment($request));
|
||||
}
|
||||
|
||||
unset($data['attachment'], $data['attachments']);
|
||||
|
||||
$document = DocumentationDocument::query()->create($data);
|
||||
$this->storeAttachments($request, $document);
|
||||
|
||||
return redirect()->route('documentation.documents.show', $document)->with('status', 'Document created successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a document.
|
||||
*/
|
||||
public function show(DocumentationDocument $document): View
|
||||
{
|
||||
return view('documentation::documents.show', [
|
||||
'document' => $document->load(['category', 'attachments']),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the edit document form.
|
||||
*/
|
||||
public function edit(DocumentationDocument $document): View
|
||||
{
|
||||
return view('documentation::documents.edit', [
|
||||
'document' => $document->load('attachments'),
|
||||
'categories' => DocumentationCategory::query()->active()->ordered()->get(),
|
||||
'statuses' => config('documentation.statuses', []),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing document.
|
||||
*/
|
||||
public function update(UpdateDocumentationDocumentRequest $request, DocumentationDocument $document): RedirectResponse
|
||||
{
|
||||
$data = $request->validated();
|
||||
$data['is_featured'] = $request->boolean('is_featured');
|
||||
$data['updated_by'] = $request->user()?->id;
|
||||
|
||||
if ($request->boolean('remove_attachment')) {
|
||||
$this->deleteAttachment($document);
|
||||
$data = array_merge($data, $this->emptyAttachmentData());
|
||||
}
|
||||
|
||||
if ($request->hasFile('attachment')) {
|
||||
$this->deleteAttachment($document);
|
||||
|
||||
if (blank($data['body'] ?? null)) {
|
||||
$data['body'] = $this->extractMarkdownBody($request) ?: ($data['body'] ?? null);
|
||||
}
|
||||
|
||||
$data = array_merge($data, $this->storeAttachment($request));
|
||||
}
|
||||
|
||||
unset($data['attachment'], $data['attachments'], $data['remove_attachment']);
|
||||
$document->update($data);
|
||||
$this->storeAttachments($request, $document);
|
||||
|
||||
return redirect()->route('documentation.documents.show', $document)->with('status', 'Document updated successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a document.
|
||||
*/
|
||||
public function destroy(DocumentationDocument $document): RedirectResponse
|
||||
{
|
||||
$document->load('attachments');
|
||||
$this->deleteAttachment($document);
|
||||
|
||||
foreach ($document->attachments as $attachment) {
|
||||
Storage::disk($attachment->disk)->delete($attachment->path);
|
||||
$attachment->delete();
|
||||
}
|
||||
|
||||
$document->delete();
|
||||
|
||||
return redirect()->route('documentation.documents.index')->with('status', 'Document archived successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the attached document file.
|
||||
*/
|
||||
public function download(DocumentationDocument $document)
|
||||
{
|
||||
abort_if(blank($document->attachment_path), 404);
|
||||
|
||||
return Storage::disk($document->attachment_disk ?: config('documentation.storage_disk', 'public'))
|
||||
->download($document->attachment_path, $document->attachment_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download one of the document's additional attachments.
|
||||
*/
|
||||
public function downloadAttachment(DocumentationDocument $document, DocumentationAttachment $attachment)
|
||||
{
|
||||
abort_if($attachment->documentation_document_id !== $document->id, 404);
|
||||
|
||||
return Storage::disk($attachment->disk)->download($attachment->path, $attachment->original_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete one of the document's additional attachments.
|
||||
*/
|
||||
public function destroyAttachment(DocumentationDocument $document, DocumentationAttachment $attachment): RedirectResponse
|
||||
{
|
||||
abort_if($attachment->documentation_document_id !== $document->id, 404);
|
||||
|
||||
Storage::disk($attachment->disk)->delete($attachment->path);
|
||||
$attachment->delete();
|
||||
|
||||
return redirect()->route('documentation.documents.edit', $document)->with('status', 'Attachment removed successfully.');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract body content from an uploaded Markdown file when requested.
|
||||
*/
|
||||
private function extractMarkdownBody(Request $request): ?string
|
||||
{
|
||||
if (! config('documentation.import_markdown_attachments', true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$file = $request->file('attachment');
|
||||
|
||||
if ($file === null || ! $this->isMarkdownUpload($request)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($file->getSize() > (int) config('documentation.max_markdown_import_bytes', 1048576)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$content = file_get_contents($file->getRealPath());
|
||||
|
||||
if ($content === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trim($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the uploaded attachment is a Markdown file.
|
||||
*/
|
||||
private function isMarkdownUpload(Request $request): bool
|
||||
{
|
||||
$file = $request->file('attachment');
|
||||
|
||||
if ($file === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$extension = strtolower($file->getClientOriginalExtension());
|
||||
$mime = strtolower((string) $file->getMimeType());
|
||||
|
||||
return $extension === 'md' || in_array($mime, ['text/markdown', 'text/x-markdown'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an uploaded attachment and return persisted metadata.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function storeAttachment(Request $request): array
|
||||
{
|
||||
$file = $request->file('attachment');
|
||||
$disk = config('documentation.storage_disk', 'public');
|
||||
$path = $file->store(config('documentation.upload_path', 'documentation'), $disk);
|
||||
|
||||
return [
|
||||
'attachment_disk' => $disk,
|
||||
'attachment_path' => $path,
|
||||
'attachment_name' => $file->getClientOriginalName(),
|
||||
'attachment_mime' => $file->getMimeType(),
|
||||
'attachment_size' => $file->getSize(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Store all additional uploaded attachments for a document.
|
||||
*/
|
||||
private function storeAttachments(Request $request, DocumentationDocument $document): void
|
||||
{
|
||||
if (! $request->hasFile('attachments')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$disk = config('documentation.storage_disk', 'public');
|
||||
|
||||
foreach ((array) $request->file('attachments') as $file) {
|
||||
if ($file === null || ! $file->isValid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $file->store(config('documentation.upload_path', 'documentation'), $disk);
|
||||
|
||||
$document->attachments()->create([
|
||||
'disk' => $disk,
|
||||
'path' => $path,
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'mime_type' => $file->getMimeType(),
|
||||
'size' => $file->getSize(),
|
||||
'uploaded_by' => $request->user()?->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a stored attachment if it exists.
|
||||
*/
|
||||
private function deleteAttachment(DocumentationDocument $document): void
|
||||
{
|
||||
if (filled($document->attachment_path)) {
|
||||
Storage::disk($document->attachment_disk ?: config('documentation.storage_disk', 'public'))->delete($document->attachment_path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty attachment metadata.
|
||||
*
|
||||
* @return array<string, null>
|
||||
*/
|
||||
private function emptyAttachmentData(): array
|
||||
{
|
||||
return [
|
||||
'attachment_disk' => null,
|
||||
'attachment_path' => null,
|
||||
'attachment_name' => null,
|
||||
'attachment_mime' => null,
|
||||
'attachment_size' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreDocumentationCategoryRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine whether the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:150'],
|
||||
'slug' => ['nullable', 'string', 'max:180', Rule::unique('documentation_categories', 'slug')],
|
||||
'icon' => ['nullable', 'string', 'max:80'],
|
||||
'colour' => ['required', 'string', 'max:32'],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'sort_order' => ['nullable', 'integer', 'min:0', 'max:999999'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Documentation\Models\DocumentationDocument;
|
||||
|
||||
class StoreDocumentationDocumentRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine whether the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'documentation_category_id' => ['nullable', 'integer', 'exists:documentation_categories,id'],
|
||||
'title' => ['required', 'string', 'max:220'],
|
||||
'slug' => ['nullable', 'string', 'max:240', Rule::unique('documentation_documents', 'slug')],
|
||||
'summary' => ['nullable', 'string', 'max:500'],
|
||||
'body' => ['nullable', 'string'],
|
||||
'status' => ['required', Rule::in([DocumentationDocument::STATUS_DRAFT, DocumentationDocument::STATUS_PUBLISHED, DocumentationDocument::STATUS_ARCHIVED])],
|
||||
'is_featured' => ['nullable', 'boolean'],
|
||||
'version' => ['required', 'string', 'max:50'],
|
||||
'reference' => ['nullable', 'string', 'max:100'],
|
||||
'attachment' => ['nullable', 'file', 'max:' . config('documentation.max_upload_kb', 20480), 'mimes:' . implode(',', config('documentation.allowed_upload_mimes', []))],
|
||||
'attachments' => ['nullable', 'array'],
|
||||
'attachments.*' => ['file', 'max:' . config('documentation.max_upload_kb', 20480), 'mimes:' . implode(',', config('documentation.allowed_upload_mimes', []))],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Documentation\Models\DocumentationCategory;
|
||||
|
||||
class UpdateDocumentationCategoryRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine whether the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var DocumentationCategory|null $category */
|
||||
$category = $this->route('category');
|
||||
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:150'],
|
||||
'slug' => ['nullable', 'string', 'max:180', Rule::unique('documentation_categories', 'slug')->ignore($category?->id)],
|
||||
'icon' => ['nullable', 'string', 'max:80'],
|
||||
'colour' => ['required', 'string', 'max:32'],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'sort_order' => ['nullable', 'integer', 'min:0', 'max:999999'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Documentation\Models\DocumentationDocument;
|
||||
|
||||
class UpdateDocumentationDocumentRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine whether the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var DocumentationDocument|null $document */
|
||||
$document = $this->route('document');
|
||||
|
||||
return [
|
||||
'documentation_category_id' => ['nullable', 'integer', 'exists:documentation_categories,id'],
|
||||
'title' => ['required', 'string', 'max:220'],
|
||||
'slug' => ['nullable', 'string', 'max:240', Rule::unique('documentation_documents', 'slug')->ignore($document?->id)],
|
||||
'summary' => ['nullable', 'string', 'max:500'],
|
||||
'body' => ['nullable', 'string'],
|
||||
'status' => ['required', Rule::in([DocumentationDocument::STATUS_DRAFT, DocumentationDocument::STATUS_PUBLISHED, DocumentationDocument::STATUS_ARCHIVED])],
|
||||
'is_featured' => ['nullable', 'boolean'],
|
||||
'version' => ['required', 'string', 'max:50'],
|
||||
'reference' => ['nullable', 'string', 'max:100'],
|
||||
'attachment' => ['nullable', 'file', 'max:' . config('documentation.max_upload_kb', 20480), 'mimes:' . implode(',', config('documentation.allowed_upload_mimes', []))],
|
||||
'attachments' => ['nullable', 'array'],
|
||||
'attachments.*' => ['file', 'max:' . config('documentation.max_upload_kb', 20480), 'mimes:' . implode(',', config('documentation.allowed_upload_mimes', []))],
|
||||
'remove_attachment' => ['nullable', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $documentation_document_id
|
||||
* @property string $disk
|
||||
* @property string $path
|
||||
* @property string $original_name
|
||||
* @property string|null $mime_type
|
||||
* @property int|null $size
|
||||
*/
|
||||
class DocumentationAttachment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/** @var list<string> */
|
||||
protected $fillable = [
|
||||
'documentation_document_id',
|
||||
'disk',
|
||||
'path',
|
||||
'original_name',
|
||||
'mime_type',
|
||||
'size',
|
||||
'uploaded_by',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
protected $casts = [
|
||||
'size' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Owning document.
|
||||
*
|
||||
* @return BelongsTo<DocumentationDocument, DocumentationAttachment>
|
||||
*/
|
||||
public function document(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DocumentationDocument::class, 'documentation_document_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a readable file size label.
|
||||
*/
|
||||
public function getSizeLabelAttribute(): string
|
||||
{
|
||||
$bytes = (int) $this->size;
|
||||
|
||||
if ($bytes <= 0) {
|
||||
return 'Unknown size';
|
||||
}
|
||||
|
||||
if ($bytes < 1024) {
|
||||
return $bytes . ' B';
|
||||
}
|
||||
|
||||
if ($bytes < 1048576) {
|
||||
return number_format($bytes / 1024, 1) . ' KB';
|
||||
}
|
||||
|
||||
return number_format($bytes / 1048576, 1) . ' MB';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $slug
|
||||
* @property string|null $icon
|
||||
* @property string $colour
|
||||
* @property string|null $description
|
||||
* @property int $sort_order
|
||||
* @property bool $is_active
|
||||
*/
|
||||
class DocumentationCategory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/** @var list<string> */
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'icon',
|
||||
'colour',
|
||||
'description',
|
||||
'sort_order',
|
||||
'is_active',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Bootstrap the model.
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (DocumentationCategory $category): void {
|
||||
if (blank($category->slug)) {
|
||||
$category->slug = Str::slug($category->name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Documents assigned to this category.
|
||||
*
|
||||
* @return HasMany<DocumentationDocument>
|
||||
*/
|
||||
public function documents(): HasMany
|
||||
{
|
||||
return $this->hasMany(DocumentationDocument::class, 'documentation_category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Active category scope.
|
||||
*
|
||||
* @param Builder<DocumentationCategory> $query
|
||||
* @return Builder<DocumentationCategory>
|
||||
*/
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ordered category scope.
|
||||
*
|
||||
* @param Builder<DocumentationCategory> $query
|
||||
* @return Builder<DocumentationCategory>
|
||||
*/
|
||||
public function scopeOrdered(Builder $query): Builder
|
||||
{
|
||||
return $query->orderBy('sort_order')->orderBy('name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int|null $documentation_category_id
|
||||
* @property string $title
|
||||
* @property string $slug
|
||||
* @property string|null $summary
|
||||
* @property string|null $body
|
||||
* @property string $status
|
||||
* @property bool $is_featured
|
||||
* @property string $version
|
||||
* @property string|null $reference
|
||||
* @property-read string $rendered_body
|
||||
*/
|
||||
class DocumentationDocument extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
public const STATUS_DRAFT = 'draft';
|
||||
public const STATUS_PUBLISHED = 'published';
|
||||
public const STATUS_ARCHIVED = 'archived';
|
||||
|
||||
/** @var list<string> */
|
||||
protected $fillable = [
|
||||
'documentation_category_id',
|
||||
'title',
|
||||
'slug',
|
||||
'summary',
|
||||
'body',
|
||||
'status',
|
||||
'is_featured',
|
||||
'version',
|
||||
'reference',
|
||||
'attachment_disk',
|
||||
'attachment_path',
|
||||
'attachment_name',
|
||||
'attachment_mime',
|
||||
'attachment_size',
|
||||
'published_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
/** @var array<string, string> */
|
||||
protected $casts = [
|
||||
'is_featured' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
'attachment_size' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Bootstrap the model.
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (DocumentationDocument $document): void {
|
||||
if (blank($document->slug)) {
|
||||
$document->slug = Str::slug($document->title);
|
||||
}
|
||||
|
||||
if ($document->status === self::STATUS_PUBLISHED && blank($document->published_at)) {
|
||||
$document->published_at = now();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Owning category.
|
||||
*
|
||||
* @return BelongsTo<DocumentationCategory, DocumentationDocument>
|
||||
*/
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DocumentationCategory::class, 'documentation_category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Document attachments.
|
||||
*
|
||||
* @return HasMany<DocumentationAttachment>
|
||||
*/
|
||||
public function attachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(DocumentationAttachment::class, 'documentation_document_id')->latest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Published document scope.
|
||||
*
|
||||
* @param Builder<DocumentationDocument> $query
|
||||
* @return Builder<DocumentationDocument>
|
||||
*/
|
||||
public function scopePublished(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', self::STATUS_PUBLISHED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Featured document scope.
|
||||
*
|
||||
* @param Builder<DocumentationDocument> $query
|
||||
* @return Builder<DocumentationDocument>
|
||||
*/
|
||||
public function scopeFeatured(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_featured', true);
|
||||
}
|
||||
/**
|
||||
* Render the document body as safe Markdown HTML for display.
|
||||
*/
|
||||
public function getRenderedBodyAttribute(): string
|
||||
{
|
||||
$body = trim((string) $this->body);
|
||||
|
||||
if ($body === '') {
|
||||
return '<p>No document body has been added yet.</p>';
|
||||
}
|
||||
|
||||
if (method_exists(Str::class, 'markdown')) {
|
||||
return (string) Str::markdown($body, [
|
||||
'html_input' => 'strip',
|
||||
'allow_unsafe_links' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
return '<p>' . nl2br(e($body), false) . '</p>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the attached file is a Markdown document.
|
||||
*/
|
||||
public function hasMarkdownAttachment(): bool
|
||||
{
|
||||
$name = strtolower((string) $this->attachment_name);
|
||||
$mime = strtolower((string) $this->attachment_mime);
|
||||
|
||||
return str_ends_with($name, '.md') || in_array($mime, ['text/markdown', 'text/x-markdown', 'text/plain'], true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The module namespace to assume when generating URLs to actions.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $moduleNamespace = 'Modules\Documentation\Http\Controllers';
|
||||
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map()
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapWebRoutes()
|
||||
{
|
||||
Route::middleware('web')
|
||||
->group(module_path('Documentation', '/Routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapApiRoutes()
|
||||
{
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->group(module_path('Documentation', '/Routes/api.php'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
@extends('documentation::layouts.master')
|
||||
|
||||
@section('title', 'Create Category')
|
||||
|
||||
@section('content')
|
||||
@include('documentation::partials.hero', [
|
||||
'title' => 'Create category',
|
||||
'subtitle' => 'Add a professional grouping for documents and operational knowledge.',
|
||||
])
|
||||
<section class="doc-card">
|
||||
<div class="doc-card-header"><strong>Category details</strong></div>
|
||||
<div class="doc-card-body">
|
||||
<form method="POST" action="{{ route('documentation.categories.store') }}">
|
||||
@include('documentation::partials.category-form')
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
@@ -0,0 +1,18 @@
|
||||
@extends('documentation::layouts.master')
|
||||
|
||||
@section('title', 'Edit Category')
|
||||
|
||||
@section('content')
|
||||
@include('documentation::partials.hero', [
|
||||
'title' => 'Edit category',
|
||||
'subtitle' => 'Update category naming, ordering, visibility, and presentation metadata.',
|
||||
])
|
||||
<section class="doc-card">
|
||||
<div class="doc-card-header"><strong>{{ $category->name }}</strong></div>
|
||||
<div class="doc-card-body">
|
||||
<form method="POST" action="{{ route('documentation.categories.update', $category) }}">
|
||||
@include('documentation::partials.category-form')
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
@@ -0,0 +1,57 @@
|
||||
@extends('documentation::layouts.master')
|
||||
|
||||
@section('title', 'Document Categories')
|
||||
|
||||
@section('content')
|
||||
@include('documentation::partials.hero', [
|
||||
'title' => 'Document categories',
|
||||
'subtitle' => 'Organise documents by policy, process, onboarding, operational support, or technical area.',
|
||||
])
|
||||
|
||||
@if(session('status'))
|
||||
<div class="doc-alert">{{ session('status') }}</div>
|
||||
@endif
|
||||
|
||||
<section class="doc-card">
|
||||
<div class="doc-card-header">
|
||||
<strong>Categories</strong>
|
||||
<a class="doc-button dark" href="{{ route('documentation.categories.create') }}">New category</a>
|
||||
</div>
|
||||
<div class="doc-card-body">
|
||||
<table class="doc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Documents</th>
|
||||
<th>Order</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($categories as $category)
|
||||
<tr>
|
||||
<td><strong>{{ $category->name }}</strong><div class="doc-muted">{{ $category->slug }}</div></td>
|
||||
<td>{{ $category->description ?: 'No description' }}</td>
|
||||
<td>{{ $category->documents_count }}</td>
|
||||
<td>{{ $category->sort_order }}</td>
|
||||
<td><span class="doc-badge {{ $category->is_active ? '' : 'archived' }}">{{ $category->is_active ? 'Active' : 'Inactive' }}</span></td>
|
||||
<td>
|
||||
<a class="doc-link" href="{{ route('documentation.categories.edit', $category) }}">Edit</a>
|
||||
<form method="POST" action="{{ route('documentation.categories.destroy', $category) }}" style="display:inline;" onsubmit="return confirm('Delete this category? Documents will become uncategorised.')">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="doc-link" style="border:0;background:none;cursor:pointer;padding:0;margin-left:10px;">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="6" class="doc-muted">No categories found.</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
<div style="margin-top:18px;">{{ $categories->links() }}</div>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
@@ -0,0 +1,18 @@
|
||||
@extends('documentation::layouts.master')
|
||||
|
||||
@section('title', 'Create Document')
|
||||
|
||||
@section('content')
|
||||
@include('documentation::partials.hero', [
|
||||
'title' => 'Create document',
|
||||
'subtitle' => 'Add a controlled document, guide, policy, SOP, upload, or operational note.',
|
||||
])
|
||||
<section class="doc-card">
|
||||
<div class="doc-card-header"><strong>Document details</strong></div>
|
||||
<div class="doc-card-body">
|
||||
<form method="POST" action="{{ route('documentation.documents.store') }}" enctype="multipart/form-data">
|
||||
@include('documentation::partials.document-form')
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
@@ -0,0 +1,25 @@
|
||||
@extends('documentation::layouts.master')
|
||||
|
||||
@section('title', 'Edit Document')
|
||||
|
||||
@section('content')
|
||||
@include('documentation::partials.hero', [
|
||||
'title' => 'Edit document',
|
||||
'subtitle' => 'Maintain document metadata, workflow status, version and attachment details.',
|
||||
])
|
||||
<section class="doc-card">
|
||||
<div class="doc-card-header"><strong>{{ $document->title }}</strong></div>
|
||||
<div class="doc-card-body">
|
||||
<form method="POST" action="{{ route('documentation.documents.update', $document) }}" enctype="multipart/form-data">
|
||||
@include('documentation::partials.document-form')
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@foreach($document->attachments as $attachment)
|
||||
<form id="delete-attachment-{{ $attachment->id }}" method="POST" action="{{ route('documentation.documents.attachments.destroy', [$document, $attachment]) }}" onsubmit="return confirm('Remove this attachment?')">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
</form>
|
||||
@endforeach
|
||||
@endsection
|
||||
@@ -0,0 +1,92 @@
|
||||
@extends('documentation::layouts.master')
|
||||
|
||||
@section('title', 'Documentation')
|
||||
|
||||
@section('content')
|
||||
@include('documentation::partials.hero', [
|
||||
'title' => 'Documentation Centre',
|
||||
'subtitle' => 'Create, control, publish, and archive operational documents from a clean professional register.',
|
||||
])
|
||||
|
||||
@if(session('status'))
|
||||
<div class="doc-alert">{{ session('status') }}</div>
|
||||
@endif
|
||||
|
||||
<section class="doc-grid stats">
|
||||
<article class="doc-card doc-stat"><strong>{{ $stats['total'] }}</strong><span>Total documents</span></article>
|
||||
<article class="doc-card doc-stat"><strong>{{ $stats['published'] }}</strong><span>Published</span></article>
|
||||
<article class="doc-card doc-stat"><strong>{{ $stats['drafts'] }}</strong><span>Drafts</span></article>
|
||||
<article class="doc-card doc-stat"><strong>{{ $stats['categories'] }}</strong><span>Categories</span></article>
|
||||
</section>
|
||||
|
||||
@if($featuredDocuments->isNotEmpty())
|
||||
<section class="doc-card" style="margin-bottom:18px;">
|
||||
<div class="doc-card-header"><strong>Featured documents</strong></div>
|
||||
<div class="doc-card-body doc-grid" style="grid-template-columns:repeat(auto-fit,minmax(220px,1fr));">
|
||||
@foreach($featuredDocuments as $featured)
|
||||
<a class="doc-card doc-card-body" style="text-decoration:none;color:inherit;box-shadow:none;" href="{{ route('documentation.documents.show', $featured) }}">
|
||||
<span class="doc-badge {{ $featured->status }}">{{ ucfirst($featured->status) }}</span>
|
||||
<h3 style="margin:12px 0 6px;">{{ $featured->title }}</h3>
|
||||
<p class="doc-muted" style="margin:0;">{{ $featured->summary ?: 'No summary provided.' }}</p>
|
||||
</a>
|
||||
@endforeach
|
||||
</div>
|
||||
</section>
|
||||
@endif
|
||||
|
||||
<section class="doc-card">
|
||||
<div class="doc-card-header">
|
||||
<strong>Document register</strong>
|
||||
<a class="doc-button dark" href="{{ route('documentation.documents.create') }}">New document</a>
|
||||
</div>
|
||||
<div class="doc-card-body">
|
||||
<form class="doc-filter" method="GET" action="{{ route('documentation.documents.index') }}">
|
||||
<input class="doc-input" name="search" value="{{ request('search') }}" placeholder="Search title, reference, summary or body">
|
||||
<select class="doc-select" name="status">
|
||||
<option value="">All statuses</option>
|
||||
@foreach($statuses as $value => $label)
|
||||
<option value="{{ $value }}" @selected(request('status') === $value)>{{ $label }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<select class="doc-select" name="category">
|
||||
<option value="">All categories</option>
|
||||
@foreach($categories as $category)
|
||||
<option value="{{ $category->id }}" @selected((string) request('category') === (string) $category->id)>{{ $category->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<button class="doc-button light" type="submit">Filter</button>
|
||||
</form>
|
||||
|
||||
<table class="doc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Document</th>
|
||||
<th>Category</th>
|
||||
<th>Status</th>
|
||||
<th>Version</th>
|
||||
<th>Updated</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($documents as $document)
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ route('documentation.documents.show', $document) }}">{{ $document->title }}</a>
|
||||
<div class="doc-muted">{{ $document->reference ?: 'No reference' }} · {{ $document->summary ?: 'No summary' }}</div>
|
||||
</td>
|
||||
<td>{{ $document->category?->name ?: 'Uncategorised' }}</td>
|
||||
<td><span class="doc-badge {{ $document->status }}">{{ ucfirst($document->status) }}</span></td>
|
||||
<td>{{ $document->version }}</td>
|
||||
<td>{{ $document->updated_at?->format('d M Y H:i') }}</td>
|
||||
<td><a class="doc-link" href="{{ route('documentation.documents.edit', $document) }}">Edit</a></td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="6" class="doc-muted">No documents found.</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
<div style="margin-top:18px;">{{ $documents->links() }}</div>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
@@ -0,0 +1,53 @@
|
||||
@extends('documentation::layouts.master')
|
||||
|
||||
@section('title', $document->title)
|
||||
|
||||
@section('content')
|
||||
@include('documentation::partials.hero', [
|
||||
'title' => $document->title,
|
||||
'subtitle' => $document->summary ?: 'Controlled documentation record with versioning, attachments and Markdown rendering.',
|
||||
'actions' => [
|
||||
['label' => 'Edit document', 'url' => route('documentation.documents.edit', $document), 'class' => 'primary'],
|
||||
['label' => 'Back to documents', 'url' => route('documentation.documents.index'), 'class' => 'secondary'],
|
||||
],
|
||||
])
|
||||
|
||||
<section class="doc-card">
|
||||
<div class="doc-card-header">
|
||||
<div>
|
||||
<strong>{{ $document->reference ?: 'Document' }}</strong>
|
||||
<div class="doc-muted">Version {{ $document->version }} @if($document->category) · {{ $document->category->name }} @endif</div>
|
||||
</div>
|
||||
<span class="doc-badge {{ $document->status }}">{{ ucfirst($document->status) }}</span>
|
||||
</div>
|
||||
<div class="doc-card-body">
|
||||
<article class="doc-content">{!! $document->rendered_body !!}</article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@if($document->attachment_name || $document->attachments->isNotEmpty())
|
||||
<section class="doc-card" style="margin-top: 18px;">
|
||||
<div class="doc-card-header"><strong>Attachments</strong></div>
|
||||
<div class="doc-card-body">
|
||||
<div class="doc-attachment-list">
|
||||
@if($document->attachment_name)
|
||||
<div class="doc-attachment-item">
|
||||
<div>
|
||||
<a class="doc-link" href="{{ route('documentation.documents.download', $document) }}">{{ $document->attachment_name }}</a>
|
||||
<span class="doc-muted">Primary file</span>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@foreach($document->attachments as $attachment)
|
||||
<div class="doc-attachment-item">
|
||||
<div>
|
||||
<a class="doc-link" href="{{ route('documentation.documents.attachments.download', [$document, $attachment]) }}">{{ $attachment->original_name }}</a>
|
||||
<span class="doc-muted">{{ $attachment->size_label }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@endif
|
||||
@endsection
|
||||
@@ -0,0 +1 @@
|
||||
@extends('documentation::documents.index')
|
||||
@@ -0,0 +1,141 @@
|
||||
<!doctype html>
|
||||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{ trim($__env->yieldContent('title', 'Documentation')) }} - {{ config('app.name', 'Laravel') }}</title>
|
||||
<style>
|
||||
:root {
|
||||
--doc-ink: #10231f;
|
||||
--doc-muted: #64748b;
|
||||
--doc-line: #dbe7e2;
|
||||
--doc-panel: #ffffff;
|
||||
--doc-soft: #f5faf8;
|
||||
--doc-brand: #0f766e;
|
||||
--doc-brand-dark: #115e59;
|
||||
--doc-accent: #16a34a;
|
||||
--doc-danger: #b91c1c;
|
||||
--doc-warning: #b45309;
|
||||
--doc-radius: 22px;
|
||||
--doc-shadow: 0 24px 70px rgba(15, 35, 31, .12);
|
||||
}
|
||||
body.documentation-module {
|
||||
margin: 0;
|
||||
background: linear-gradient(135deg, #eef8f3 0%, #f8fafc 45%, #ecfdf5 100%);
|
||||
color: var(--doc-ink);
|
||||
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.doc-shell { max-width: 1240px; margin: 0 auto; padding: 28px 20px 56px; }
|
||||
.doc-hero {
|
||||
display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center;
|
||||
padding: 28px; border-radius: 30px; color: #fff;
|
||||
background: radial-gradient(circle at top left, rgba(255,255,255,.24), transparent 34%), linear-gradient(135deg, #064e3b, #0f766e 52%, #16a34a);
|
||||
box-shadow: var(--doc-shadow); margin-bottom: 22px;
|
||||
}
|
||||
.doc-eyebrow { text-transform: uppercase; font-size: 12px; letter-spacing: .16em; font-weight: 800; opacity: .82; margin: 0 0 10px; }
|
||||
.doc-hero h1 { margin: 0; font-size: clamp(30px, 5vw, 52px); line-height: .98; letter-spacing: -.04em; }
|
||||
.doc-hero p { max-width: 720px; margin: 14px 0 0; color: rgba(255,255,255,.84); font-size: 16px; line-height: 1.65; }
|
||||
.doc-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
|
||||
.doc-button {
|
||||
border: 1px solid transparent; border-radius: 999px; padding: 11px 16px; font-weight: 800; font-size: 14px;
|
||||
text-decoration: none; display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
|
||||
}
|
||||
.doc-button.primary { background: #fff; color: var(--doc-brand-dark); }
|
||||
.doc-button.secondary { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.32); }
|
||||
.doc-button.dark { background: var(--doc-brand); color: #fff; }
|
||||
.doc-button.light { background: #f8fafc; color: var(--doc-ink); border-color: var(--doc-line); }
|
||||
.doc-button.danger { background: #fef2f2; color: var(--doc-danger); border-color: #fecaca; padding: 8px 12px; }
|
||||
.doc-card { background: rgba(255,255,255,.92); border: 1px solid var(--doc-line); border-radius: var(--doc-radius); box-shadow: 0 14px 45px rgba(15,35,31,.08); overflow: hidden; }
|
||||
.doc-card-header { padding: 20px 22px; border-bottom: 1px solid var(--doc-line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
|
||||
.doc-card-body { padding: 22px; }
|
||||
.doc-grid { display: grid; gap: 18px; }
|
||||
.doc-grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 22px 0; }
|
||||
.doc-stat { padding: 20px; }
|
||||
.doc-stat strong { display:block; font-size: 30px; letter-spacing: -.04em; }
|
||||
.doc-stat span { color: var(--doc-muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
|
||||
.doc-table { width: 100%; border-collapse: collapse; }
|
||||
.doc-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--doc-muted); padding: 12px; border-bottom: 1px solid var(--doc-line); }
|
||||
.doc-table td { padding: 14px 12px; border-bottom: 1px solid #edf3f0; vertical-align: top; }
|
||||
.doc-table a { color: var(--doc-brand-dark); font-weight: 800; text-decoration: none; }
|
||||
.doc-badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 800; background: #ecfdf5; color: #065f46; border: 1px solid #bbf7d0; }
|
||||
.doc-badge.draft { background: #f8fafc; color: #475569; border-color: #cbd5e1; }
|
||||
.doc-badge.archived { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
|
||||
.doc-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
|
||||
.doc-field.full { grid-column: 1 / -1; }
|
||||
.doc-label { display: block; font-weight: 800; margin-bottom: 8px; font-size: 14px; }
|
||||
.doc-input, .doc-select, .doc-textarea {
|
||||
width: 100%; box-sizing: border-box; border: 1px solid #cbd5e1; border-radius: 14px; padding: 12px 14px;
|
||||
background: #fff; color: var(--doc-ink); font: inherit;
|
||||
}
|
||||
.doc-textarea { min-height: 360px; line-height: 1.6; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
|
||||
.doc-editor { border: 1px solid #cbd5e1; border-radius: 16px; overflow: hidden; background: #fff; }
|
||||
.doc-editor .doc-textarea { border: 0; border-radius: 0; min-height: 420px; }
|
||||
.doc-editor-toolbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; background: #f8fafc; border-bottom: 1px solid var(--doc-line); }
|
||||
.doc-editor-toolbar button { border: 1px solid #cbd5e1; background: #fff; color: var(--doc-ink); border-radius: 10px; padding: 7px 10px; font-weight: 800; cursor: pointer; }
|
||||
.doc-editor-toolbar button:hover, .doc-editor-toolbar button:focus { border-color: var(--doc-brand); outline: 2px solid rgba(15, 118, 110, .18); }
|
||||
.editor-help { padding: 0 14px 12px; margin: -4px 0 0; font-size: 13px; }
|
||||
.doc-error { color: var(--doc-danger); font-size: 13px; margin-top: 6px; }
|
||||
.doc-alert { border-radius: 16px; padding: 14px 16px; background: #ecfdf5; color: #065f46; border: 1px solid #bbf7d0; margin-bottom: 18px; font-weight: 700; }
|
||||
.doc-filter { display: grid; grid-template-columns: 1fr 180px 220px auto; gap: 12px; margin-bottom: 18px; }
|
||||
.doc-content { line-height: 1.75; font-size: 16px; }
|
||||
.doc-content h1, .doc-content h2, .doc-content h3 { line-height: 1.2; letter-spacing: -.025em; margin: 1.4em 0 .55em; }
|
||||
.doc-content h1 { font-size: 2rem; }
|
||||
.doc-content h2 { font-size: 1.55rem; border-bottom: 1px solid var(--doc-line); padding-bottom: .35rem; }
|
||||
.doc-content h3 { font-size: 1.25rem; }
|
||||
.doc-content p, .doc-content ul, .doc-content ol, .doc-content blockquote, .doc-content pre { margin: 0 0 1rem; }
|
||||
.doc-content code { background: #f1f5f9; border-radius: 7px; padding: .14rem .32rem; font-size: .92em; }
|
||||
.doc-content pre { overflow-x: auto; background: #0f172a; color: #e2e8f0; border-radius: 16px; padding: 16px; }
|
||||
.doc-content pre code { background: transparent; color: inherit; padding: 0; }
|
||||
.doc-content blockquote { border-left: 4px solid var(--doc-brand); padding-left: 16px; color: var(--doc-muted); }
|
||||
.doc-content table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
|
||||
.doc-content th, .doc-content td { border: 1px solid var(--doc-line); padding: 10px 12px; text-align: left; }
|
||||
.doc-muted { color: var(--doc-muted); }
|
||||
.doc-link { color: var(--doc-brand-dark); font-weight: 800; text-decoration: none; }
|
||||
.doc-attachment-list { display: grid; gap: 10px; }
|
||||
.doc-attachment-item { display: flex; justify-content: space-between; align-items: center; gap: 14px; border: 1px solid var(--doc-line); border-radius: 14px; padding: 12px 14px; background: #fff; }
|
||||
@media (max-width: 860px) {
|
||||
.doc-hero { grid-template-columns: 1fr; }
|
||||
.doc-grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
.doc-filter, .doc-form-grid { grid-template-columns: 1fr; }
|
||||
.doc-table { display: block; overflow-x: auto; }
|
||||
}
|
||||
@media (max-width: 560px) {
|
||||
.doc-shell { padding: 16px 12px 36px; }
|
||||
.doc-hero { padding: 22px; border-radius: 22px; }
|
||||
.doc-grid.stats { grid-template-columns: 1fr; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="documentation-module">
|
||||
<main class="doc-shell">
|
||||
@yield('content')
|
||||
</main>
|
||||
<script>
|
||||
document.addEventListener('click', function (event) {
|
||||
const button = event.target.closest('[data-md-before]');
|
||||
|
||||
if (! button) {
|
||||
return;
|
||||
}
|
||||
|
||||
const editor = button.closest('[data-documentation-editor]');
|
||||
const textarea = editor ? editor.querySelector('[data-markdown-textarea]') : null;
|
||||
|
||||
if (! textarea) {
|
||||
return;
|
||||
}
|
||||
|
||||
const before = button.getAttribute('data-md-before') || '';
|
||||
const after = button.getAttribute('data-md-after') || '';
|
||||
const start = textarea.selectionStart || 0;
|
||||
const end = textarea.selectionEnd || 0;
|
||||
const selected = textarea.value.substring(start, end);
|
||||
const replacement = before + selected + after;
|
||||
|
||||
textarea.setRangeText(replacement, start, end, 'end');
|
||||
textarea.focus();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,43 @@
|
||||
@csrf
|
||||
@if($category->exists)
|
||||
@method('PUT')
|
||||
@endif
|
||||
<div class="doc-form-grid">
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="name">Name</label>
|
||||
<input class="doc-input" id="name" name="name" value="{{ old('name', $category->name) }}" required maxlength="150">
|
||||
@error('name') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="slug">Slug</label>
|
||||
<input class="doc-input" id="slug" name="slug" value="{{ old('slug', $category->slug) }}" maxlength="180" placeholder="Auto-generated when blank">
|
||||
@error('slug') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="icon">Icon</label>
|
||||
<input class="doc-input" id="icon" name="icon" value="{{ old('icon', $category->icon) }}" maxlength="80" placeholder="book-open, file-check, shield">
|
||||
@error('icon') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="colour">Colour</label>
|
||||
<input class="doc-input" id="colour" name="colour" value="{{ old('colour', $category->colour ?: 'emerald') }}" required maxlength="32">
|
||||
@error('colour') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="sort_order">Sort order</label>
|
||||
<input class="doc-input" id="sort_order" name="sort_order" type="number" min="0" value="{{ old('sort_order', $category->sort_order ?: 0) }}">
|
||||
@error('sort_order') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field" style="display:flex;align-items:end;">
|
||||
<label><input type="checkbox" name="is_active" value="1" @checked(old('is_active', $category->is_active ?? true))> Active category</label>
|
||||
</div>
|
||||
<div class="doc-field full">
|
||||
<label class="doc-label" for="description">Description</label>
|
||||
<textarea class="doc-textarea" id="description" name="description" style="min-height:140px;">{{ old('description', $category->description) }}</textarea>
|
||||
@error('description') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
</div>
|
||||
<div class="doc-actions" style="margin-top:22px;">
|
||||
<button class="doc-button dark" type="submit">Save category</button>
|
||||
<a class="doc-button light" href="{{ route('documentation.categories.index') }}">Cancel</a>
|
||||
</div>
|
||||
@@ -0,0 +1,109 @@
|
||||
@csrf
|
||||
@if($document->exists)
|
||||
@method('PUT')
|
||||
@endif
|
||||
|
||||
<div class="doc-form-grid">
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="title">Title</label>
|
||||
<input class="doc-input" id="title" name="title" value="{{ old('title', $document->title) }}" required maxlength="220">
|
||||
@error('title') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="slug">Slug</label>
|
||||
<input class="doc-input" id="slug" name="slug" value="{{ old('slug', $document->slug) }}" maxlength="240" placeholder="Auto-generated when blank">
|
||||
@error('slug') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="documentation_category_id">Category</label>
|
||||
<select class="doc-select" id="documentation_category_id" name="documentation_category_id">
|
||||
<option value="">No category</option>
|
||||
@foreach($categories as $category)
|
||||
<option value="{{ $category->id }}" @selected((string) old('documentation_category_id', $document->documentation_category_id) === (string) $category->id)>{{ $category->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('documentation_category_id') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="status">Status</label>
|
||||
<select class="doc-select" id="status" name="status" required>
|
||||
@foreach($statuses as $value => $label)
|
||||
<option value="{{ $value }}" @selected(old('status', $document->status) === $value)>{{ $label }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('status') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="version">Version</label>
|
||||
<input class="doc-input" id="version" name="version" value="{{ old('version', $document->version ?: '1.0.0') }}" required maxlength="50">
|
||||
@error('version') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field">
|
||||
<label class="doc-label" for="reference">Reference</label>
|
||||
<input class="doc-input" id="reference" name="reference" value="{{ old('reference', $document->reference) }}" maxlength="100" placeholder="SOP-001, POL-002, etc.">
|
||||
@error('reference') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field full">
|
||||
<label class="doc-label" for="summary">Summary</label>
|
||||
<input class="doc-input" id="summary" name="summary" value="{{ old('summary', $document->summary) }}" maxlength="500">
|
||||
@error('summary') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field full">
|
||||
<label class="doc-label" for="body">Document body</label>
|
||||
<div class="doc-editor" data-documentation-editor>
|
||||
<div class="doc-editor-toolbar" aria-label="Markdown editor controls">
|
||||
<button type="button" data-md-before="## " data-md-after="" title="Heading">H2</button>
|
||||
<button type="button" data-md-before="**" data-md-after="**" title="Bold"><strong>B</strong></button>
|
||||
<button type="button" data-md-before="_" data-md-after="_" title="Italic"><em>I</em></button>
|
||||
<button type="button" data-md-before="> " data-md-after="" title="Quote">Quote</button>
|
||||
<button type="button" data-md-before="- " data-md-after="" title="Bullet list">List</button>
|
||||
<button type="button" data-md-before="1. " data-md-after="" title="Numbered list">1.</button>
|
||||
<button type="button" data-md-before="[" data-md-after="](https://)" title="Link">Link</button>
|
||||
<button type="button" data-md-before="`" data-md-after="`" title="Inline code">Code</button>
|
||||
<button type="button" data-md-before="```php " data-md-after=" ```" title="Code block">Code block</button>
|
||||
<button type="button" data-md-before="| Column | Column | | --- | --- | | Value | Value |" data-md-after="" title="Table">Table</button>
|
||||
</div>
|
||||
<textarea class="doc-textarea" id="body" name="body" data-markdown-textarea>{{ old('body', $document->body) }}</textarea>
|
||||
<p class="doc-muted editor-help">Markdown is supported, including fenced code blocks such as <code>```php</code>, tables, lists, links, and headings.</p>
|
||||
</div>
|
||||
@error('body') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field full">
|
||||
<label class="doc-label" for="attachment">Primary attachment</label>
|
||||
<input class="doc-input" id="attachment" name="attachment" type="file">
|
||||
<p class="doc-muted">Primary Markdown files can be imported into the document body when the body is blank.</p>
|
||||
@if($document->attachment_name)
|
||||
<p class="doc-muted">Current primary file: <a class="doc-link" href="{{ route('documentation.documents.download', $document) }}">{{ $document->attachment_name }}</a></p>
|
||||
<label><input type="checkbox" name="remove_attachment" value="1"> Remove current primary attachment</label>
|
||||
@endif
|
||||
@error('attachment') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
</div>
|
||||
<div class="doc-field full">
|
||||
<label class="doc-label" for="attachments">Additional attachments</label>
|
||||
<input class="doc-input" id="attachments" name="attachments[]" type="file" multiple>
|
||||
<p class="doc-muted">Attach supporting files such as PDFs, screenshots, spreadsheets, Word documents, Markdown, CSV, and images.</p>
|
||||
@error('attachments') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
@error('attachments.*') <div class="doc-error">{{ $message }}</div> @enderror
|
||||
|
||||
@if($document->exists && $document->attachments->isNotEmpty())
|
||||
<div class="doc-attachment-list" style="margin-top: 14px;">
|
||||
@foreach($document->attachments as $attachment)
|
||||
<div class="doc-attachment-item">
|
||||
<div>
|
||||
<a class="doc-link" href="{{ route('documentation.documents.attachments.download', [$document, $attachment]) }}">{{ $attachment->original_name }}</a>
|
||||
<span class="doc-muted">{{ $attachment->size_label }}</span>
|
||||
</div>
|
||||
<button class="doc-button danger" type="submit" form="delete-attachment-{{ $attachment->id }}">Remove</button>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="doc-field full">
|
||||
<label><input type="checkbox" name="is_featured" value="1" @checked(old('is_featured', $document->is_featured))> Feature this document on the dashboard</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="doc-actions" style="margin-top:22px;">
|
||||
<button class="doc-button dark" type="submit">Save document</button>
|
||||
<a class="doc-button light" href="{{ route('documentation.documents.index') }}">Cancel</a>
|
||||
</div>
|
||||
@@ -0,0 +1,13 @@
|
||||
<section class="doc-hero">
|
||||
<div>
|
||||
<p class="doc-eyebrow">{{ $eyebrow ?? 'Documentation Suite' }}</p>
|
||||
<h1>{{ $title ?? 'Documentation' }}</h1>
|
||||
<p>{{ $subtitle ?? 'Manage controlled documents, policies, guides, files, and operational knowledge in one professional workspace.' }}</p>
|
||||
<div class="doc-actions">
|
||||
<a class="doc-button primary" href="{{ route('documentation.documents.create') }}">Create document</a>
|
||||
<a class="doc-button secondary" href="{{ route('documentation.categories.index') }}">Manage categories</a>
|
||||
<a class="doc-button secondary" href="{{ route('documentation.documents.index') }}">Document register</a>
|
||||
</div>
|
||||
</div>
|
||||
<div aria-hidden="true" style="width:140px;height:140px;border-radius:32px;background:rgba(255,255,255,.16);display:grid;place-items:center;border:1px solid rgba(255,255,255,.26);font-size:58px;font-weight:900;">D</div>
|
||||
</section>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('documentation')->name('api.documentation.')->group(function (): void {
|
||||
Route::get('/status', static fn (): array => [
|
||||
'module' => 'documentation',
|
||||
'status' => 'ok',
|
||||
'version' => '1.1.0',
|
||||
])->name('status');
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Documentation\Http\Controllers\DocumentationCategoryController;
|
||||
use Modules\Documentation\Http\Controllers\DocumentationController;
|
||||
|
||||
Route::prefix(config('documentation.route_prefix', 'documentation'))
|
||||
->name('documentation.')
|
||||
->middleware(config('documentation.middleware', ['web', 'auth']))
|
||||
->group(function (): void {
|
||||
Route::get('/', [DocumentationController::class, 'index'])->name('index');
|
||||
Route::get('/documents', [DocumentationController::class, 'index'])->name('documents.index');
|
||||
Route::get('/documents/create', [DocumentationController::class, 'create'])->name('documents.create');
|
||||
Route::post('/documents', [DocumentationController::class, 'store'])->name('documents.store');
|
||||
Route::get('/documents/{document}', [DocumentationController::class, 'show'])->name('documents.show');
|
||||
Route::get('/documents/{document}/edit', [DocumentationController::class, 'edit'])->name('documents.edit');
|
||||
Route::put('/documents/{document}', [DocumentationController::class, 'update'])->name('documents.update');
|
||||
Route::delete('/documents/{document}', [DocumentationController::class, 'destroy'])->name('documents.destroy');
|
||||
Route::get('/documents/{document}/download', [DocumentationController::class, 'download'])->name('documents.download');
|
||||
Route::get('/documents/{document}/attachments/{attachment}/download', [DocumentationController::class, 'downloadAttachment'])->name('documents.attachments.download');
|
||||
Route::delete('/documents/{document}/attachments/{attachment}', [DocumentationController::class, 'destroyAttachment'])->name('documents.attachments.destroy');
|
||||
|
||||
Route::resource('categories', DocumentationCategoryController::class)->except(['show']);
|
||||
});
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documentation\Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
use Modules\Documentation\Models\DocumentationCategory;
|
||||
use Modules\Documentation\Models\DocumentationDocument;
|
||||
use Modules\Documentation\Models\DocumentationAttachment;
|
||||
|
||||
class DocumentationModuleTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* The documentation dashboard renders for authenticated users.
|
||||
*/
|
||||
public function test_documentation_dashboard_renders(): void
|
||||
{
|
||||
$user = \App\Models\User::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('documentation.documents.index'))
|
||||
->assertOk()
|
||||
->assertSee('Documentation Centre');
|
||||
}
|
||||
|
||||
/**
|
||||
* Documents can be created through the CRUD endpoint.
|
||||
*/
|
||||
public function test_document_can_be_created(): void
|
||||
{
|
||||
$user = \App\Models\User::factory()->create();
|
||||
$category = DocumentationCategory::query()->create([
|
||||
'name' => 'Operations',
|
||||
'slug' => 'operations',
|
||||
'colour' => 'emerald',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->post(route('documentation.documents.store'), [
|
||||
'documentation_category_id' => $category->id,
|
||||
'title' => 'Goods In Process',
|
||||
'slug' => 'goods-in-process',
|
||||
'summary' => 'Inbound warehouse process.',
|
||||
'body' => 'Step-by-step goods in process.',
|
||||
'status' => DocumentationDocument::STATUS_PUBLISHED,
|
||||
'version' => '1.0.0',
|
||||
'reference' => 'SOP-001',
|
||||
'is_featured' => '1',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$this->assertDatabaseHas('documentation_documents', [
|
||||
'title' => 'Goods In Process',
|
||||
'status' => DocumentationDocument::STATUS_PUBLISHED,
|
||||
'reference' => 'SOP-001',
|
||||
'is_featured' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Markdown attachments are stored and imported into the document body.
|
||||
*/
|
||||
public function test_markdown_attachment_is_imported_and_rendered(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$user = \App\Models\User::factory()->create();
|
||||
$file = UploadedFile::fake()->createWithContent('goods-in.md', "# Goods In\n\n- Scan delivery note\n- Confirm quantities");
|
||||
|
||||
$response = $this->actingAs($user)->post(route('documentation.documents.store'), [
|
||||
'title' => 'Goods In Markdown',
|
||||
'slug' => 'goods-in-markdown',
|
||||
'summary' => 'Markdown controlled document.',
|
||||
'body' => '',
|
||||
'status' => DocumentationDocument::STATUS_PUBLISHED,
|
||||
'version' => '1.0.0',
|
||||
'attachment' => $file,
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
|
||||
$document = DocumentationDocument::query()->where('slug', 'goods-in-markdown')->firstOrFail();
|
||||
|
||||
$this->assertStringContainsString('# Goods In', (string) $document->body);
|
||||
$this->assertStringContainsString('<h1>Goods In</h1>', $document->rendered_body);
|
||||
Storage::disk('public')->assertExists($document->attachment_path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Multiple supporting attachments can be uploaded, downloaded and removed.
|
||||
*/
|
||||
public function test_document_supports_multiple_attachments(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$user = \App\Models\User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('documentation.documents.store'), [
|
||||
'title' => 'Attachment Pack',
|
||||
'slug' => 'attachment-pack',
|
||||
'summary' => 'Document with supporting files.',
|
||||
'body' => 'Attach evidence and supporting material.',
|
||||
'status' => DocumentationDocument::STATUS_PUBLISHED,
|
||||
'version' => '1.0.0',
|
||||
'attachments' => [
|
||||
UploadedFile::fake()->createWithContent('setup.md', "```php\necho 'ok';\n```"),
|
||||
UploadedFile::fake()->create('process.pdf', 64, 'application/pdf'),
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
|
||||
$document = DocumentationDocument::query()->where('slug', 'attachment-pack')->firstOrFail();
|
||||
|
||||
$this->assertCount(2, $document->attachments()->get());
|
||||
|
||||
$attachment = $document->attachments()->where('original_name', 'setup.md')->firstOrFail();
|
||||
Storage::disk('public')->assertExists($attachment->path);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('documentation.documents.attachments.download', [$document, $attachment]))
|
||||
->assertOk();
|
||||
|
||||
$this->actingAs($user)
|
||||
->delete(route('documentation.documents.attachments.destroy', [$document, $attachment]))
|
||||
->assertRedirect(route('documentation.documents.edit', $document));
|
||||
|
||||
$this->assertDatabaseMissing('documentation_attachments', ['id' => $attachment->id]);
|
||||
Storage::disk('public')->assertMissing($attachment->path);
|
||||
}
|
||||
|
||||
/**
|
||||
* The editor renders Markdown controls for code blocks and tables.
|
||||
*/
|
||||
public function test_document_editor_has_markdown_code_controls(): void
|
||||
{
|
||||
$user = \App\Models\User::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('documentation.documents.create'))
|
||||
->assertOk()
|
||||
->assertSee('data-documentation-editor', false)
|
||||
->assertSee('Code block')
|
||||
->assertSee('Markdown is supported');
|
||||
}
|
||||
|
||||
/**
|
||||
* Categories can be created through the CRUD endpoint.
|
||||
*/
|
||||
public function test_category_can_be_created(): void
|
||||
{
|
||||
$user = \App\Models\User::factory()->create();
|
||||
|
||||
$this->actingAs($user)->post(route('documentation.categories.store'), [
|
||||
'name' => 'Policies',
|
||||
'slug' => 'policies',
|
||||
'colour' => 'emerald',
|
||||
'description' => 'Controlled business policies.',
|
||||
'sort_order' => 1,
|
||||
'is_active' => '1',
|
||||
])->assertRedirect(route('documentation.categories.index'));
|
||||
|
||||
$this->assertDatabaseHas('documentation_categories', [
|
||||
'name' => 'Policies',
|
||||
'slug' => 'policies',
|
||||
'is_active' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
version: 1.4.0
|
||||
date: 2026-06-15
|
||||
changes:
|
||||
- Added professional documentation dashboard and document CRUD.
|
||||
- Added document categories with status, ordering, colour, and icon support.
|
||||
- Added migrations, Eloquent models, form requests, routes, and feature coverage.
|
||||
- Added self-contained Abbott-style module views with accessible responsive styling.
|
||||
- Added Markdown upload processing for .md files with safe rendered HTML preview.
|
||||
- Added Markdown import coverage and styling for headings, code blocks, tables, and blockquotes.
|
||||
- Added multiple supporting attachments per document with upload, download, removal, storage cleanup, and tests.
|
||||
- Added a free built-in Markdown editor toolbar with controls for headings, bold, italic, quotes, lists, links, inline code, fenced code blocks, and tables.
|
||||
- Added WMS Support sidebar integration for Documentation, New Document, and Categories links using the existing sidebar colour scheme and active-state conventions.
|
||||
- Added a root documentation.index route while preserving documentation.documents.index for CRUD navigation.
|
||||
- Fixed module composer metadata and synced module.json version.
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "mpba/documentation",
|
||||
"description": "Professional documentation and document management module.",
|
||||
"type": "laravel-module",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mark Gregory",
|
||||
"email": "mark.gregory@mpba.co.uk"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [],
|
||||
"aliases": {}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\Documentation\\": ""
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Modules\\Documentation\\Tests\\": "Tests/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "Documentation",
|
||||
"alias": "documentation",
|
||||
"version": "1.4.0",
|
||||
"description": "Professional document management and knowledge-base module with categories, CRUD, publishing, Markdown editing/import support, code blocks, attachments, and WMS Support navigation integration.",
|
||||
"keywords": [
|
||||
"documentation",
|
||||
"documents",
|
||||
"knowledge-base",
|
||||
"crud"
|
||||
],
|
||||
"priority": 0,
|
||||
"providers": [
|
||||
"Modules\\Documentation\\Providers\\DocumentationServiceProvider"
|
||||
],
|
||||
"aliases": {},
|
||||
"files": [],
|
||||
"requires": []
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# WMS support navigation integration
|
||||
|
||||
Replace the existing `{{-- Support Portal --}} ... {{-- Support Portal end --}}` block in the application shell with:
|
||||
|
||||
```blade
|
||||
@include('partials.wms-support-navigation')
|
||||
```
|
||||
|
||||
The partial keeps the existing WMS sidebar classes, FontAwesome icon pattern, `wire:navigate`, mobile-close behaviour, and active-state conventions.
|
||||
@@ -0,0 +1,98 @@
|
||||
{{-- Support Portal + Documentation --}}
|
||||
@php
|
||||
$helpdeskEnabled = Route::has('helpdesk.index') || Route::has('helpdesk.tickets.index');
|
||||
$documentationEnabled = Route::has('documentation.documents.index') || Route::has('documentation.categories.index');
|
||||
|
||||
$helpdeskSettingsRoute = Route::has('helpdesk.settings')
|
||||
? 'helpdesk.settings'
|
||||
: (Route::has('helpdesk.settings.index') ? 'helpdesk.settings.index' : null);
|
||||
|
||||
$helpdeskKanbanRoute = Route::has('helpdesk.kanban')
|
||||
? 'helpdesk.kanban'
|
||||
: (Route::has('helpdesk.kanban.index') ? 'helpdesk.kanban.index' : null);
|
||||
|
||||
$helpdeskGitRoute = Route::has('helpdesk.git.index')
|
||||
? 'helpdesk.git.index'
|
||||
: null;
|
||||
|
||||
$helpdeskWorkflowRoute = Route::has('helpdesk.workflow-templates.index')
|
||||
? 'helpdesk.workflow-templates.index'
|
||||
: null;
|
||||
@endphp
|
||||
|
||||
@if($helpdeskEnabled || $documentationEnabled)
|
||||
<div class="wms-sidebar-group">
|
||||
<div class="wms-sidebar-heading" data-wms-sidebar-label>{{ __('Support') }}</div>
|
||||
|
||||
@if(Route::has('helpdesk.index'))
|
||||
<a href="{{ route('helpdesk.index') }}" wire:navigate class="wms-sidebar-link @if(request()->routeIs('helpdesk.index')) is-active @endif" title="{{ __('Helpdesk Dashboard') }}">
|
||||
<i class="fa-solid fa-headset wms-sidebar-icon" aria-hidden="true"></i>
|
||||
<span data-wms-sidebar-label>{{ __('Dashboard') }}</span>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if(Route::has('helpdesk.tickets.index'))
|
||||
<a href="{{ route('helpdesk.tickets.index') }}" wire:navigate class="wms-sidebar-link @if(request()->routeIs('helpdesk.tickets.*')) is-active @endif" title="{{ __('Tickets') }}">
|
||||
<i class="fa-solid fa-ticket wms-sidebar-icon" aria-hidden="true"></i>
|
||||
<span data-wms-sidebar-label>{{ __('Tickets') }}</span>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if(Route::has('helpdesk.tickets.create'))
|
||||
<a href="{{ route('helpdesk.tickets.create') }}" wire:navigate class="wms-sidebar-link @if(request()->routeIs('helpdesk.tickets.create')) is-active @endif" title="{{ __('Raise Ticket') }}">
|
||||
<i class="fa-solid fa-circle-plus wms-sidebar-icon" aria-hidden="true"></i>
|
||||
<span data-wms-sidebar-label>{{ __('Raise Ticket') }}</span>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if($helpdeskKanbanRoute)
|
||||
<a href="{{ route($helpdeskKanbanRoute) }}" wire:navigate class="wms-sidebar-link @if(request()->routeIs('helpdesk.kanban*')) is-active @endif" title="{{ __('Kanban') }}">
|
||||
<i class="fa-solid fa-table-columns wms-sidebar-icon" aria-hidden="true"></i>
|
||||
<span data-wms-sidebar-label>{{ __('Kanban') }}</span>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if($documentationEnabled)
|
||||
<a href="{{ route('documentation.documents.index') }}" wire:navigate class="wms-sidebar-link @if(request()->routeIs('documentation.documents.*')) is-active @endif" title="{{ __('Documentation') }}">
|
||||
<i class="fa-solid fa-book-open-reader wms-sidebar-icon" aria-hidden="true"></i>
|
||||
<span data-wms-sidebar-label>{{ __('Documentation') }}</span>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if(Route::has('documentation.documents.create'))
|
||||
<a href="{{ route('documentation.documents.create') }}" wire:navigate class="wms-sidebar-link @if(request()->routeIs('documentation.documents.create')) is-active @endif" title="{{ __('New Document') }}">
|
||||
<i class="fa-solid fa-file-circle-plus wms-sidebar-icon" aria-hidden="true"></i>
|
||||
<span data-wms-sidebar-label>{{ __('New Document') }}</span>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if(Route::has('documentation.categories.index'))
|
||||
<a href="{{ route('documentation.categories.index') }}" wire:navigate class="wms-sidebar-link @if(request()->routeIs('documentation.categories.*')) is-active @endif" title="{{ __('Document Categories') }}">
|
||||
<i class="fa-solid fa-folder-tree wms-sidebar-icon" aria-hidden="true"></i>
|
||||
<span data-wms-sidebar-label>{{ __('Categories') }}</span>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if($helpdeskGitRoute)
|
||||
<a href="{{ route($helpdeskGitRoute) }}" wire:navigate class="wms-sidebar-link @if(request()->routeIs('helpdesk.git.*')) is-active @endif" title="{{ __('Git Tracking') }}">
|
||||
<i class="fa-solid fa-code-commit wms-sidebar-icon" aria-hidden="true"></i>
|
||||
<span data-wms-sidebar-label>{{ __('Git Tracking') }}</span>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if($helpdeskWorkflowRoute)
|
||||
<a href="{{ route($helpdeskWorkflowRoute) }}" wire:navigate class="wms-sidebar-link @if(request()->routeIs('helpdesk.workflow-templates.*')) is-active @endif" title="{{ __('Workflow Emails') }}">
|
||||
<i class="fa-solid fa-envelope-circle-check wms-sidebar-icon" aria-hidden="true"></i>
|
||||
<span data-wms-sidebar-label>{{ __('Workflow Emails') }}</span>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
@if($helpdeskSettingsRoute)
|
||||
<a href="{{ route($helpdeskSettingsRoute) }}" wire:navigate class="wms-sidebar-link @if(request()->routeIs('helpdesk.settings*')) is-active @endif" title="{{ __('Helpdesk Settings') }}">
|
||||
<i class="fa-solid fa-gears wms-sidebar-icon" aria-hidden="true"></i>
|
||||
<span data-wms-sidebar-label>{{ __('Settings') }}</span>
|
||||
</a>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
{{-- Support Portal + Documentation end --}}
|
||||
Reference in New Issue
Block a user