- Added DocumentController for handling document uploads and management. - Created Document model with necessary attributes and relationships. - Implemented DocumentService for business logic related to documents. - Set up routes for document management in both web and API contexts. - Developed views for document upload using Dropzone for file handling. - Included necessary assets and styles for the Document module. - Created migration for documents table with appropriate fields. - Added configuration and service provider for the Document module.
50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\Document\Services;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\Document\Models\Document;
|
|
|
|
class DocumentService
|
|
{
|
|
|
|
public function getAllCategories()
|
|
{
|
|
$query = Document::query();
|
|
return $query->get();
|
|
}
|
|
|
|
public function storeDocument(array $documentData): Document
|
|
{
|
|
return DB::transaction(function () use ($documentData) {
|
|
$document = Document::create($documentData);
|
|
|
|
return $document;
|
|
});
|
|
}
|
|
|
|
public function getDocumentById(int $id)
|
|
{
|
|
return Document::findOrFail($id);
|
|
}
|
|
|
|
public function updateDocument(int $id, array $documentData)
|
|
{
|
|
$document = $this->getDocumentById($id);
|
|
|
|
return DB::transaction(function () use ($document, $documentData) {
|
|
$document->update($documentData);
|
|
return $document;
|
|
});
|
|
}
|
|
|
|
public function deleteDocument(int $id)
|
|
{
|
|
return DB::transaction(function () use ($id) {
|
|
$document = $this->getDocumentById($id);
|
|
$document->delete();
|
|
return true;
|
|
});
|
|
}
|
|
}
|