raffles document uploader added / Free Resource Completed

This commit is contained in:
2025-08-03 00:01:49 +05:45
parent efa9231391
commit a3b863970e
25 changed files with 472 additions and 1062 deletions

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Traits;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Modules\Document\Models\Document;
trait AddToDocumentCollection
{
public function addToDocumentCollection(string $collectionName = 'uploads', string $file, ?string $documentName = null, ?int $referenceDocumentId = null)
{
if (!Storage::disk('public')->exists($collectionName)) {
Storage::disk('public')->makeDirectory($collectionName);
}
$targetFile = Storage::disk('public')->path("{$collectionName}/{$file}");
File::copy(storage_path("tmp/uploads/{$file}"), $targetFile);
$this->documents()->create([
'title' => $documentName,
'file_path' => $file,
'collection_name' => $collectionName,
]);
}
public function documents(): MorphMany
{
return $this->morphMany(Document::class, 'documentable')->orderBy('order');
}
}