Company logo added media manager
This commit is contained in:
parent
675b1ba42a
commit
e3b736d3e8
@ -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');
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -61,8 +61,31 @@
|
||||
$('#company_logo').fancyfile({
|
||||
text : '{{ trans('general.form.select.file') }}',
|
||||
style : 'btn-default',
|
||||
placeholder : '<?php echo $company->company_logo; ?>'
|
||||
@if($company->logo)
|
||||
placeholder : '<?php echo $company->logo->basename; ?>'
|
||||
@endif
|
||||
});
|
||||
|
||||
@if($company->logo)
|
||||
attachment_html = '<span class="attachment">';
|
||||
attachment_html += ' <a href="{{ url('uploads/' . $company->logo->id . '/download') }}">';
|
||||
attachment_html += ' <span id="download-attachment" class="text-primary">';
|
||||
attachment_html += ' <i class="fa fa-file-{{ $company->logo->aggregate_type }}-o"></i> {{ $company->logo->basename }}';
|
||||
attachment_html += ' </span>';
|
||||
attachment_html += ' </a>';
|
||||
attachment_html += ' {!! Form::open(['id' => 'attachment-' . $company->logo->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $company->logo->id)], 'style' => 'display:inline']) !!}';
|
||||
attachment_html += ' <a id="remove-attachment" href="javascript:void();">';
|
||||
attachment_html += ' <span class="text-danger"><i class="fa fa fa-times"></i></span>';
|
||||
attachment_html += ' </a>';
|
||||
attachment_html += ' {!! Form::close() !!}';
|
||||
attachment_html += '</span>';
|
||||
|
||||
$('.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' => '<strong>' . $company->logo->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
|
||||
});
|
||||
@endif
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
Loading…
x
Reference in New Issue
Block a user