added upload

This commit is contained in:
vedatakd 2021-09-13 18:32:48 +03:00
parent cc9f6c343b
commit 58bf4b85e7
2 changed files with 32 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -58,4 +58,6 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
public function currentAds();
public function findByCFJSON($key, $value);
public function uploadImage();
}