mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Upload company logo to group settings
This commit is contained in:
parent
db3ccaf4bc
commit
cc85746af0
@ -33,6 +33,7 @@ use App\Repositories\BaseRepository;
|
||||
use App\Repositories\ClientRepository;
|
||||
use App\Transformers\ClientTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\Uploadable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@ -45,7 +46,8 @@ use Illuminate\Support\Facades\Log;
|
||||
class ClientController extends BaseController
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
use Uploadable;
|
||||
|
||||
protected $entity_type = Client::class;
|
||||
|
||||
protected $entity_transformer = ClientTransformer::class;
|
||||
@ -283,21 +285,7 @@ class ClientController extends BaseController
|
||||
|
||||
$client = $this->client_repo->save($request->all(), $client);
|
||||
|
||||
if($request->file('company_logo'))
|
||||
{
|
||||
\Log::error('settings logo present');
|
||||
|
||||
$path = UploadAvatar::dispatchNow($request->file('company_logo'), $client->company->company_key);
|
||||
|
||||
if($path){
|
||||
|
||||
$settings = $client->settings;
|
||||
$settings->company_logo_url = $client->company->domain . $path;
|
||||
$client->settings = $settings;
|
||||
$client->save();
|
||||
}
|
||||
|
||||
}
|
||||
$this->uploadLogo($request->file('company_logo'), $client->company, $client);
|
||||
|
||||
return $this->itemResponse($client);
|
||||
|
||||
@ -398,6 +386,8 @@ class ClientController extends BaseController
|
||||
|
||||
$client->load('contacts', 'primary_contact');
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $client->company, $client);
|
||||
|
||||
return $this->itemResponse($client);
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ use App\Transformers\AccountTransformer;
|
||||
use App\Transformers\CompanyTransformer;
|
||||
use App\Transformers\CompanyUserTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\Uploadable;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@ -44,6 +45,7 @@ class CompanyController extends BaseController
|
||||
{
|
||||
use DispatchesJobs;
|
||||
use MakesHash;
|
||||
use Uploadable;
|
||||
|
||||
protected $entity_type = Company::class;
|
||||
|
||||
@ -205,20 +207,7 @@ class CompanyController extends BaseController
|
||||
|
||||
$company = CreateCompany::dispatchNow($request->all(), auth()->user()->company()->account);
|
||||
|
||||
if($request->file('company_logo'))
|
||||
{
|
||||
|
||||
$path = UploadAvatar::dispatchNow($request->file('company_logo'), $company->company_key);
|
||||
|
||||
if($path){
|
||||
|
||||
$settings = $company->settings;
|
||||
$settings->company_logo_url = $company->domain . $path;
|
||||
$company->settings = $settings;
|
||||
$company->save();
|
||||
}
|
||||
|
||||
}
|
||||
$this->uploadLogo($request->file('company_logo'), $company, $company);
|
||||
|
||||
auth()->user()->companies()->attach($company->id, [
|
||||
'account_id' => $company->account->id,
|
||||
@ -420,20 +409,7 @@ class CompanyController extends BaseController
|
||||
{
|
||||
$company = $this->company_repo->save($request->all(), $company);
|
||||
|
||||
if($request->file('company_logo'))
|
||||
{
|
||||
\Log::error('logo present');
|
||||
$path = UploadAvatar::dispatchNow($request->file('company_logo'), $company->company_key);
|
||||
|
||||
if($path){
|
||||
|
||||
$settings = $company->settings;
|
||||
$settings->company_logo_url = $company->domain . $path;
|
||||
$company->settings = $settings;
|
||||
$company->save();
|
||||
}
|
||||
|
||||
}
|
||||
$this->uploadLogo($request->file('company_logo'), $company, $company);
|
||||
|
||||
return $this->itemResponse($company);
|
||||
}
|
||||
|
@ -22,12 +22,14 @@ use App\Http\Requests\GroupSetting\UpdateGroupSettingRequest;
|
||||
use App\Models\GroupSetting;
|
||||
use App\Repositories\GroupSettingRepository;
|
||||
use App\Transformers\GroupSettingTransformer;
|
||||
use App\Utils\Traits\Uploadable;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GroupSettingController extends BaseController
|
||||
{
|
||||
use DispatchesJobs;
|
||||
use Uploadable;
|
||||
|
||||
protected $entity_type = GroupSetting::class;
|
||||
|
||||
@ -184,6 +186,8 @@ class GroupSettingController extends BaseController
|
||||
|
||||
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $group_setting->company, $group_setting);
|
||||
|
||||
return $this->itemResponse($group_setting);
|
||||
|
||||
}
|
||||
@ -352,8 +356,10 @@ class GroupSettingController extends BaseController
|
||||
public function update(UpdateGroupSettingRequest $request, GroupSetting $group_setting)
|
||||
{
|
||||
|
||||
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
|
||||
|
||||
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $group_setting->company, $group_setting);
|
||||
|
||||
return $this->itemResponse($group_setting);
|
||||
|
||||
}
|
||||
|
38
app/Utils/Traits/Uploadable.php
Normal file
38
app/Utils/Traits/Uploadable.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Utils\Traits;
|
||||
|
||||
|
||||
/**
|
||||
* Class Uploadable
|
||||
* @package App\Utils\Traits
|
||||
*/
|
||||
trait Uploadable
|
||||
{
|
||||
public function uploadLogo($file, $company, $entity)
|
||||
{
|
||||
if(($file)
|
||||
{
|
||||
|
||||
$path = UploadAvatar::dispatchNow(($file, $company->company_key);
|
||||
|
||||
if($path){
|
||||
|
||||
$settings = $entity->settings;
|
||||
$settings->company_logo_url = $company->domain . $path;
|
||||
$entity->settings = $settings;
|
||||
$entity->save();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user