fipamo/app/Http/Controllers/API/FileUploadAPIController.php

46 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\Assets\FileUploadService;
use App\Interfaces\MemberRepositoryInterface;
use App\Services\Data\SettingsService;
class FileUploadAPIController extends Controller
{
protected $upload;
protected $member;
protected $settings;
public function __construct(
FileUploadService $fileUploadService,
MemberRepositoryInterface $memberRepo,
SettingsService $settingsService
) {
$this->upload = $fileUploadService;
$this->member = $memberRepo;
$this->settings = $settingsService;
}
public function upload(Request $request)
{
$result = $this->upload->handleFile($request);
//update configs for specfic uploads
switch ($request['source']) {
case 'avatar-upload':
$member = [];
$member = session('member');
$member['avatar'] = $result['filePath'];
$member = (object) $member;
$this->member->update($member);
break;
case 'background-upload':
$this->settings->updateGlobalData('background', $result['filePath']);
break;
}
return $result;
}
}