50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Shipping extends Model
|
|
{
|
|
protected $table = 'shippings';
|
|
|
|
protected $casts = [
|
|
'trans_name' => 'array',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'name', 'active', 'free'
|
|
];
|
|
|
|
public function _format_number($value){
|
|
return preg_replace("/[^0-9,]/", "", $value);
|
|
}
|
|
|
|
public function setFreeAttribute( $value ) {
|
|
if($value == ""){
|
|
$this->attributes['free'] = null;
|
|
}else{
|
|
$value = $this->_format_number($value);
|
|
$this->attributes['free'] = floatval(str_replace(',', '.', $value));
|
|
}
|
|
}
|
|
public function getFormattedFree()
|
|
{
|
|
if($this->free === null) {
|
|
return "";
|
|
}
|
|
if(\App::getLocale() == "en"){
|
|
return number_format($this->attributes['free'], 2, '.', ',');
|
|
}
|
|
return number_format($this->attributes['free'], 2, ',', '.');
|
|
}
|
|
|
|
|
|
public function countries(){
|
|
return $this->hasMany('App\Models\ShippingCountry', 'shipping_id', 'id');
|
|
}
|
|
|
|
public function prices(){
|
|
return $this->hasMany('App\Models\ShippingPrice', 'shipping_id', 'id');
|
|
}
|
|
}
|