added attribute casting

This commit is contained in:
Denis Duliçi
2020-11-13 15:15:27 +03:00
parent 9deac6b1f3
commit 2d7c18bae5
13 changed files with 108 additions and 99 deletions

View File

@ -24,6 +24,15 @@ class Contact extends Model
*/
protected $fillable = ['company_id', 'type', 'name', 'email', 'user_id', 'tax_number', 'phone', 'address', 'website', 'currency_code', 'reference', 'enabled'];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'enabled' => 'boolean',
];
/**
* Sortable columns.
*

View File

@ -19,6 +19,15 @@ class Dashboard extends Model
*/
protected $fillable = ['company_id', 'name', 'enabled'];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'enabled' => 'boolean',
];
/**
* Sortable columns.
*

View File

@ -28,6 +28,17 @@ class Item extends Model
*/
protected $fillable = ['company_id', 'name', 'description', 'sale_price', 'purchase_price', 'category_id', 'tax_id', 'enabled'];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'sale_price' => 'double',
'purchase_price' => 'double',
'enabled' => 'boolean',
];
/**
* Sortable columns.
*
@ -60,28 +71,6 @@ class Item extends Model
return $query->where('name', '=', $name);
}
/**
* Convert sale price to double.
*
* @param string $value
* @return void
*/
public function setSalePriceAttribute($value)
{
$this->attributes['sale_price'] = (double) $value;
}
/**
* Convert purchase price to double.
*
* @param string $value
* @return void
*/
public function setPurchasePriceAttribute($value)
{
$this->attributes['purchase_price'] = (double) $value;
}
/**
* Get the item id.
*

View File

@ -19,7 +19,7 @@ class Report extends Model
protected $fillable = ['company_id', 'class', 'name', 'description', 'settings'];
/**
* The attributes that should be casted to native types.
* The attributes that should be cast.
*
* @var array
*/

View File

@ -19,7 +19,7 @@ class Widget extends Model
protected $fillable = ['company_id', 'dashboard_id', 'class', 'name', 'sort', 'settings'];
/**
* The attributes that should be casted to native types.
* The attributes that should be cast.
*
* @var array
*/