1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/app/Utils/Traits/Uploadable.php

52 lines
1.2 KiB
PHP
Raw Normal View History

2019-10-07 23:17:55 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2019-10-07 23:17:55 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
2019-10-07 23:17:55 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Utils\Traits;
use App\Jobs\Util\UnlinkFile;
2019-10-08 00:07:43 +02:00
use App\Jobs\Util\UploadAvatar;
use Illuminate\Support\Facades\Storage;
2019-10-08 00:07:43 +02:00
2019-10-07 23:17:55 +02:00
/**
* Class Uploadable.
2019-10-07 23:17:55 +02:00
*/
trait Uploadable
{
public function removeLogo($company)
{
$company_logo = $company->settings->company_logo;
$file_name = basename($company_logo);
$storage_path = $company->company_key . '/' . $file_name;
if (Storage::exists($storage_path)) {
UnlinkFile::dispatchNow(config('filesystems.default'), $storage_path);
}
}
public function uploadLogo($file, $company, $entity)
{
if ($file) {
2019-10-07 23:43:25 +02:00
$path = UploadAvatar::dispatchNow($file, $company->company_key);
2019-10-07 23:17:55 +02:00
info("the path {$path}");
2020-06-18 01:25:08 +02:00
if ($path) {
2019-10-07 23:17:55 +02:00
$settings = $entity->settings;
2020-02-27 00:32:44 +01:00
$settings->company_logo = $path;
2019-10-07 23:17:55 +02:00
$entity->settings = $settings;
$entity->save();
}
}
}
}