close #191 Fixed : When trying to edit Companies. it is broken

This commit is contained in:
cuneytsenturk
2018-01-16 14:37:02 +03:00
parent 3d2122e9a4
commit 75531ee718
3 changed files with 45 additions and 34 deletions

View File

@ -92,20 +92,30 @@ class Version119 extends Listener
$items = $data[basename($model)]; $items = $data[basename($model)];
foreach ($items as $item) { foreach ($items as $item) {
if ($item->$name) { if (!$item->$name) {
$path = explode('uploads/', $item->$name); continue;
}
$path = end($path); $path = explode('uploads/', $item->$name);
if (!empty($item->company_id) && (strpos($path, $item->company_id . '/') === false)) { $path = end($path);
$path = $item->company_id . '/' . $path;
}
if (!empty($path) && Storage::exists($path)) { if (!empty($item->company_id) && (strpos($path, $item->company_id . '/') === false)) {
$media = MediaUploader::importPath(config('mediable.default_disk'), $path); $path = $item->company_id . '/' . $path;
}
if (!empty($path) && Storage::exists($path)) {
$media = \App\Models\Common\Media::where('filename', '=', pathinfo(basename($path), PATHINFO_FILENAME))->first();
if ($media) {
$item->attachMedia($media, $name); $item->attachMedia($media, $name);
continue;
} }
$media = MediaUploader::importPath(config('mediable.default_disk'), $path);
$item->attachMedia($media, $name);
} }
} }
} }
@ -115,34 +125,36 @@ class Version119 extends Listener
foreach ($settings as $name => $items) { foreach ($settings as $name => $items) {
foreach ($items as $item) { foreach ($items as $item) {
if ($item->value) { if (!$item->value) {
$path = explode('uploads/', $item->value); continue;
}
$path = end($path); $path = explode('uploads/', $item->value);
if (!empty($item->company_id) && (strpos($path, $item->company_id . '/') === false)) { $path = end($path);
$path = $item->company_id . '/' . $path;
}
if (!empty($path) && Storage::exists($path)) { if (!empty($item->company_id) && (strpos($path, $item->company_id . '/') === false)) {
$company = \App\Models\Company\Company::find($item->company_id); $path = $item->company_id . '/' . $path;
}
$media = \App\Models\Common\Media::where('filename', '=', pathinfo(basename($path), PATHINFO_FILENAME))->first(); if (!empty($path) && Storage::exists($path)) {
$company = \App\Models\Company\Company::find($item->company_id);
if ($company && !$media) { $media = \App\Models\Common\Media::where('filename', '=', pathinfo(basename($path), PATHINFO_FILENAME))->first();
$media = MediaUploader::importPath(config('mediable.default_disk'), $path);
$company->attachMedia($media, $name); if ($company && !$media) {
$media = MediaUploader::importPath(config('mediable.default_disk'), $path);
$item->update(['value' => $media->id]); $company->attachMedia($media, $name);
} elseif ($media) {
$item->update(['value' => $media->id]); $item->update(['value' => $media->id]);
} else { } elseif ($media) {
$item->update(['value' => '']); $item->update(['value' => $media->id]);
}
} else { } else {
$item->update(['value' => '']); $item->update(['value' => '']);
} }
} else {
$item->update(['value' => '']);
} }
} }
} }

View File

@ -236,14 +236,8 @@ class Company extends Eloquent
* *
* @return string * @return string
*/ */
public function getCompanyLogoAttribute($value) public function getCompanyLogoAttribute()
{ {
if (!empty($value) && !$this->hasMedia('company_logo')) {
return $value;
} elseif (!$this->hasMedia('company_logo')) {
return false;
}
return $this->getMedia('company_logo')->last(); return $this->getMedia('company_logo')->last();
} }
} }

5
public/css/app.css vendored
View File

@ -538,3 +538,8 @@ ul.add-new.nav.navbar-nav.pull-left {
margin-top: 25px; margin-top: 25px;
margin-bottom: 10px; margin-bottom: 10px;
} }
span.picture, span.attachment {
margin-left: 10px;
vertical-align: middle;
}