diff --git a/app/Http/Controllers/ClientPortal/UploadController.php b/app/Http/Controllers/ClientPortal/UploadController.php index f2daf077680b..78bb9b820173 100644 --- a/app/Http/Controllers/ClientPortal/UploadController.php +++ b/app/Http/Controllers/ClientPortal/UploadController.php @@ -18,7 +18,7 @@ class UploadController extends Controller */ public function __invoke(StoreUploadRequest $request) { - $this->saveDocuments($request->getFile(), auth()->user()->client); + $this->saveDocuments($request->getFile(), auth()->user()->client, true); return response([], 200); } diff --git a/app/Http/Livewire/DownloadsTable.php b/app/Http/Livewire/DownloadsTable.php index 28bc99447e01..0f90291dd294 100644 --- a/app/Http/Livewire/DownloadsTable.php +++ b/app/Http/Livewire/DownloadsTable.php @@ -28,7 +28,7 @@ class DownloadsTable extends Component public function render() { - $query = auth()->user()->client->documents(); + $query = auth('contact')->user()->client->documents(); if (in_array('resources', $this->status) && !in_array('client', $this->status)) { $query = $query->where('documentable_type', '!=', 'App\Models\Client'); @@ -39,6 +39,7 @@ class DownloadsTable extends Component } $query = $query + ->where('is_public', true) ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); diff --git a/app/Jobs/Util/UploadFile.php b/app/Jobs/Util/UploadFile.php index ce8d500dcd02..e451ac47d6f7 100644 --- a/app/Jobs/Util/UploadFile.php +++ b/app/Jobs/Util/UploadFile.php @@ -44,10 +44,11 @@ class UploadFile implements ShouldQueue protected $user; protected $company; protected $type; + protected $is_public; public $entity; - public function __construct($file, $type, $user, $company, $entity, $disk = null) + public function __construct($file, $type, $user, $company, $entity, $disk = null, $is_public = false) { $this->file = $file; $this->type = $type; @@ -55,6 +56,7 @@ class UploadFile implements ShouldQueue $this->company = $company; $this->entity = $entity; $this->disk = $disk ?? config('filesystems.default'); + $this->is_public = $is_public; //MultiDB::setDB($this->company->db); } @@ -96,6 +98,7 @@ class UploadFile implements ShouldQueue $document->size = $this->file->getSize(); $document->width = isset($width) ? $width : null; $document->height = isset($height) ? $height : null; + $document->is_public = $this->is_public; // $preview_path = $this->encodePrimaryKey($this->company->id); // $document->preview = $this->generatePreview($preview_path); diff --git a/app/Utils/Traits/SavesDocuments.php b/app/Utils/Traits/SavesDocuments.php index f953a7a3f112..1a0644fb311f 100644 --- a/app/Utils/Traits/SavesDocuments.php +++ b/app/Utils/Traits/SavesDocuments.php @@ -17,7 +17,7 @@ use App\Models\Company; trait SavesDocuments { - public function saveDocuments($document_array, $entity) + public function saveDocuments($document_array, $entity, $is_public = false) { if ($entity instanceof Company) { $account = $entity->account; @@ -37,7 +37,9 @@ trait SavesDocuments UploadFile::DOCUMENT, $entity->user, $entity->company, - $entity + $entity, + null, + $is_public ); } } diff --git a/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php new file mode 100644 index 000000000000..f5d7664aefa7 --- /dev/null +++ b/database/migrations/2020_08_18_140557_add_is_public_to_documents_table.php @@ -0,0 +1,32 @@ +boolean('is_public')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('documents', function (Blueprint $table) { + $table->dropColumn('is_public'); + }); + } +}