Merge pull request #1164 from openclassify/vedat

added upload
This commit is contained in:
Fatih Alp 2021-09-13 18:34:14 +03:00 committed by GitHub
commit 8c5450a5a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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();
}