diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index 874e2073a..c34007876 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -14,6 +14,7 @@ use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface; use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\LocationModule\District\DistrictModel; +use Visiosoft\MediaFieldType\Http\Controller\UploadController; class AdvRepository extends EntryRepository implements AdvRepositoryInterface { @@ -562,4 +563,33 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface ->whereJsonContains('cf_json', [$key => $value]) ->first(); } + + public function uploadImage() + { + $folder_repository = app(FolderRepositoryInterface::class); + + if (request()->has(['adv_id', 'upload']) + and $adv = $this->newQuery()->find(request('adv_id')) + and $folder = $folder_repository->findBySlug('images')) { + + + $upload_service = app(UploadController::class); + + request()->offsetSet('folder', $folder->id); + + if ($response = $upload_service->upload()) { + + $file_id = $response->getData()->id; + + DB::table('advs_advs_files')->insert([ + 'entry_id' => $adv->id, + 'file_id' => $file_id + ]); + + return true; + } + } + + return false; + } } diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php index e46160f54..53e667867 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php @@ -58,4 +58,6 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface public function currentAds(); public function findByCFJSON($key, $value); + + public function uploadImage(); }