forked from projects/fipamo
avatar and background image upload fixed
uploading new member avatar and background images weren't uploading to the correct location and the approprate files weren't being updated, so that was been fixed. the folks template in the init directory also needed be updated because the system was looking for 'avatar' instead of 'avi' which was resulting in some mismatch calls that were resulting in not found errors. the variable is now 'avatar' everywhere for the sake of consistency.
This commit is contained in:
parent
cd056336cd
commit
91aa2703b6
4 changed files with 32 additions and 9 deletions
|
@ -5,18 +5,41 @@ 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)
|
||||
{
|
||||
$this->upload = $fileUploadService;
|
||||
public function __construct(
|
||||
FileUploadService $fileUploadService,
|
||||
MemberRepositoryInterface $memberRepo,
|
||||
SettingsService $settingsService
|
||||
) {
|
||||
$this->upload = $fileUploadService;
|
||||
$this->member = $memberRepo;
|
||||
$this->settings = $settingsService;
|
||||
}
|
||||
|
||||
public function upload(Request $request, $type = null)
|
||||
{
|
||||
return $this->upload->handleFile($request, $type);
|
||||
$result = $this->upload->handleFile($request, $type);
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,10 +54,10 @@ class MemberRepository implements MemberRepositoryInterface
|
|||
|
||||
public function update($member)
|
||||
{
|
||||
//TODO: need to add member avatar updating
|
||||
$index = findIndex($this->folks, ['id' => $member->id]);
|
||||
$this->folks[$index]['handle'] = $member->handle;
|
||||
$this->folks[$index]['email'] = $member->email;
|
||||
$this->folks[$index]['avatar'] = $member->avatar;
|
||||
$this->folks[$index]['updated'] = Carbon::now();
|
||||
//save new folks file
|
||||
$this->docs::writeSettings($this->folks, env('FOLKS_PATH'));
|
||||
|
@ -77,7 +77,7 @@ class MemberRepository implements MemberRepositoryInterface
|
|||
'handle' => $found['handle'],
|
||||
'email' => $found['email'],
|
||||
'role' => $found['role'],
|
||||
'avatar' => $found['avi'],
|
||||
'avatar' => $found['avatar'],
|
||||
'key' => $found['key'],
|
||||
'secret' => $found['secret'],
|
||||
];
|
||||
|
|
|
@ -23,8 +23,8 @@ class FileUploadService
|
|||
case 'jpg':
|
||||
case 'png':
|
||||
case 'gif':
|
||||
if (isset($options["source"])) {
|
||||
if ($options["source"] == "avatar-upload") {
|
||||
if (isset($request["source"])) {
|
||||
if ($request["source"] == "avatar-upload") {
|
||||
$filesPath = '/assets/images/user/' . $path . '/';
|
||||
//Member::updateData('avi', $filesPath . $file->getClientFileName());
|
||||
} else {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{
|
||||
"id": "",
|
||||
"handle": "",
|
||||
"avi": "/assets/images/global/default-avi.png",
|
||||
"avatar": "/assets/images/global/default-avi.png",
|
||||
"email": "",
|
||||
"password": "",
|
||||
"key": "",
|
||||
|
|
Loading…
Reference in a new issue