sigd/app/Models/SigdModel.php

58 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema;
class SigdModel extends Model
{
use HasFactory;
public $incrementing = false;
protected $keyType = 'string';
public function scopeRowActive($query)
{
return $query->where('row_status', 1);
}
public function scopeIsActive($query)
{
return $query->where('active_status', 1);
}
public function scopeOrderByRowNum($query)
{
$table = $this->getTable();
if (Schema::hasColumn($table, 'row_num')) {
return $query->orderBy('row_num', 'asc');
}
return $query;
}
// public function getValueAttribute($value)
// {
// $table = $this->getTable();
// if (Schema::hasColumn($table, 'value')) {
// $value = (float) $value; // Convert the value to a float to handle scientific notation
// $value = number_format($value, 10, ',', '.'); // Convert back to a string with custom formatting
// $value = rtrim(rtrim($value, '0'), ','); // Remove unnecessary zeros and trailing commas
// return $value;
// }
// return $value;
// }
// public function setValueAttribute($value)
// {
// $table = $this->getTable();
// if (Schema::hasColumn($table, 'value')) {
// $value = str_replace(',', '.', str_replace('.', '', $value)); // Remove any thousand separators and replace comma
// $this->attributes['value'] = $value;
// } else {
// $this->attributes['value'] = $value; // Handle default behavior if 'value' column does not exist
// }
// }
}