invoiceninja/app/Utils/Traits/Uploadable.php

45 lines
1.1 KiB
PHP
Raw Normal View History

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