diff --git a/app/Http/Controllers/Companies/Companies.php b/app/Http/Controllers/Companies/Companies.php
index 2af1bdf36..c36f832a4 100644
--- a/app/Http/Controllers/Companies/Companies.php
+++ b/app/Http/Controllers/Companies/Companies.php
@@ -59,9 +59,16 @@ class Companies extends Controller
setting()->set('general.company_email', $request->get('company_email'));
setting()->set('general.company_address', $request->get('company_address'));
- $logo_path = $this->getUploadedFilePath($request->file('company_logo'), 'settings', $company->id);
- if ($logo_path) {
- setting()->set('general.company_logo', $logo_path);
+ if ($request->file('company_logo')) {
+ $logo = $this->getMedia($request->file('company_logo'), 'settings', $company->id);
+
+ if ($logo) {
+ $company->attachMedia($logo, 'logo');
+
+ $logo_path = $logo->directory . '/' . $logo->basename;
+
+ setting()->set('general.company_logo', $logo_path);
+ }
}
setting()->set('general.default_currency', $request->get('default_currency'));
@@ -135,9 +142,16 @@ class Companies extends Controller
setting()->set('general.company_email', $request->get('company_email'));
setting()->set('general.company_address', $request->get('company_address'));
- $logo_path = $this->getUploadedFilePath($request->file('company_logo'), 'settings', $company->id);
- if ($logo_path) {
- setting()->set('general.company_logo', $logo_path);
+ if ($request->file('company_logo')) {
+ $logo = $this->getMedia($request->file('company_logo'), 'settings', $company->id);
+
+ if ($logo) {
+ $company->attachMedia($logo, 'logo');
+
+ $logo_path = $logo->directory . '/' . $logo->basename;
+
+ setting()->set('general.company_logo', $logo_path);
+ }
}
setting()->set('general.default_payment_method', 'offlinepayment.cash.1');
diff --git a/app/Models/Company/Company.php b/app/Models/Company/Company.php
index 893778fe5..3c0953e73 100644
--- a/app/Models/Company/Company.php
+++ b/app/Models/Company/Company.php
@@ -7,10 +7,11 @@ use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\SoftDeletes;
use Kyslik\ColumnSortable\Sortable;
+use Plank\Mediable\Mediable;
class Company extends Eloquent
{
- use Filterable, SoftDeletes, Sortable;
+ use Filterable, SoftDeletes, Sortable, Mediable;
protected $table = 'companies';
@@ -229,4 +230,18 @@ class Company extends Eloquent
->orderBy('value', $direction)
->select('companies.*');
}
+
+ /**
+ * Get the current balance.
+ *
+ * @return string
+ */
+ public function getLogoAttribute()
+ {
+ if (!$this->hasMedia('logo')) {
+ return false;
+ }
+
+ return $this->getMedia('logo')->last();
+ }
}
diff --git a/app/Traits/Uploads.php b/app/Traits/Uploads.php
index a4364158b..8adfbd28c 100644
--- a/app/Traits/Uploads.php
+++ b/app/Traits/Uploads.php
@@ -30,8 +30,14 @@ trait Uploads
return $path;
}
- public function getMedia($file, $folder, $company_id = null)
+ public function getMedia($file, $folder = 'settings', $company_id = null)
{
+ $path = '';
+
+ if (!$file || !$file->isValid()) {
+ return $path;
+ }
+
if (!$company_id) {
$company_id = session('company_id');
}
diff --git a/resources/views/companies/companies/edit.blade.php b/resources/views/companies/companies/edit.blade.php
index ad66c0155..f3f64f50b 100644
--- a/resources/views/companies/companies/edit.blade.php
+++ b/resources/views/companies/companies/edit.blade.php
@@ -61,8 +61,31 @@
$('#company_logo').fancyfile({
text : '{{ trans('general.form.select.file') }}',
style : 'btn-default',
- placeholder : 'company_logo; ?>'
+ @if($company->logo)
+ placeholder : 'logo->basename; ?>'
+ @endif
});
+
+ @if($company->logo)
+ attachment_html = '';
+ attachment_html += ' ';
+ attachment_html += ' ';
+ attachment_html += ' {{ $company->logo->basename }}';
+ attachment_html += ' ';
+ attachment_html += ' ';
+ attachment_html += ' {!! Form::open(['id' => 'attachment-' . $company->logo->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $company->logo->id)], 'style' => 'display:inline']) !!}';
+ attachment_html += ' ';
+ attachment_html += ' ';
+ attachment_html += ' ';
+ attachment_html += ' {!! Form::close() !!}';
+ attachment_html += '';
+
+ $('.fancy-file .fake-file').append(attachment_html);
+
+ $(document).on('click', '#remove-attachment', function (e) {
+ confirmDelete("#attachment-{!! $company->logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $company->logo->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
+ });
+ @endif
});
@endpush