Migration move media table and fixed attribute issue

This commit is contained in:
cuneytsenturk 2018-01-03 20:08:56 +03:00
parent 3c15d3e96f
commit 5788233c2e
10 changed files with 72 additions and 8 deletions

View File

@ -24,5 +24,33 @@ class Version116 extends Listener
return; return;
} }
$migrations = [
'\App\Models\Auth\User' => 'picture',
'\App\Models\Item\Item' => 'picture',
'\App\Models\Expense\Bill' => 'attachment',
'\App\Models\Expense\BillPayment' => 'attachment',
'\App\Models\Expense\Payment' => 'attachment',
'\App\Models\Income\Invoice' => 'attachment',
'\App\Models\Income\InvoicePayment' => 'attachment',
'\App\Models\Income\Revenue' => 'attachment',
];
foreach ($migrations as $model => $name) {
if ($model != '\App\Models\Auth\User') {
$items = $model::where('company_id', '<>', '0')->get();
} else {
$items = $model::all();
}
foreach ($items as $item) {
if ($item->$name) {
$path = explode('uploads/', $item->$name);
$media = MediaUploader::importPath(config('mediable.default_disk'), $path[1]);
$item->attachMedia($media, $name);
}
}
}
} }
} }

View File

@ -89,6 +89,10 @@ class User extends Authenticatable
} }
} }
if (!empty($value)) {
return $value;
}
if (!$this->hasMedia('picture')) { if (!$this->hasMedia('picture')) {
return false; return false;
} }

View File

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

View File

@ -135,8 +135,12 @@ class Bill extends Model
* *
* @return string * @return string
*/ */
public function getAttachmentAttribute() public function getAttachmentAttribute($value)
{ {
if (!empty($value)) {
return $value;
}
if (!$this->hasMedia('attachment')) { if (!$this->hasMedia('attachment')) {
return false; return false;
} }

View File

@ -85,8 +85,12 @@ class BillPayment extends Model
* *
* @return string * @return string
*/ */
public function getAttachmentAttribute() public function getAttachmentAttribute($value)
{ {
if (!empty($value)) {
return $value;
}
if (!$this->hasMedia('attachment')) { if (!$this->hasMedia('attachment')) {
return false; return false;
} }

View File

@ -98,8 +98,12 @@ class Payment extends Model
* *
* @return string * @return string
*/ */
public function getAttachmentAttribute() public function getAttachmentAttribute($value)
{ {
if (!empty($value)) {
return $value;
}
if (!$this->hasMedia('attachment')) { if (!$this->hasMedia('attachment')) {
return false; return false;
} }

View File

@ -144,8 +144,12 @@ class Invoice extends Model
* *
* @return string * @return string
*/ */
public function getAttachmentAttribute() public function getAttachmentAttribute($value)
{ {
if (!empty($value)) {
return $value;
}
if (!$this->hasMedia('attachment')) { if (!$this->hasMedia('attachment')) {
return false; return false;
} }

View File

@ -85,8 +85,12 @@ class InvoicePayment extends Model
* *
* @return string * @return string
*/ */
public function getAttachmentAttribute() public function getAttachmentAttribute($value)
{ {
if (!empty($value)) {
return $value;
}
if (!$this->hasMedia('attachment')) { if (!$this->hasMedia('attachment')) {
return false; return false;
} }

View File

@ -104,8 +104,12 @@ class Revenue extends Model
* *
* @return string * @return string
*/ */
public function getAttachmentAttribute() public function getAttachmentAttribute($value)
{ {
if (!empty($value)) {
return $value;
}
if (!$this->hasMedia('attachment')) { if (!$this->hasMedia('attachment')) {
return false; return false;
} }

View File

@ -118,8 +118,12 @@ class Item extends Model
* *
* @return string * @return string
*/ */
public function getPictureAttribute() public function getPictureAttribute($value)
{ {
if (!empty($value)) {
return $value;
}
if (!$this->hasMedia('picture')) { if (!$this->hasMedia('picture')) {
return false; return false;
} }