You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
946 B
PHP
34 lines
946 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class TvLog extends Model {
|
|
use HasFactory;
|
|
|
|
protected $table = 'tv_logs';
|
|
protected $hidden = ['ik_cust_id', 'ik_address_id'];
|
|
protected $casts = ['from'=>'object', 'to'=>'object'];
|
|
|
|
const TYPE_CREATE = 'create';
|
|
const TYPE_UPDATE = 'update';
|
|
const TYPES = ['create', 'update'];
|
|
public static function saveHistory(String $type, int $tvFk, ?Tv $oldTv, ?Tv $newTv) {
|
|
if(!in_array($type, self::TYPES)) throw new \Exception("Type '$type' No Valid");
|
|
$tvLog = new TvLog();
|
|
$tvLog->tv_fk = $tvFk;
|
|
$tvLog->type = $type;
|
|
if($oldTv) {
|
|
$oldTv = $oldTv->toArray();
|
|
$tvLog->from =$oldTv;
|
|
}
|
|
if($newTv) {
|
|
$newTv = $newTv->toArray();
|
|
$tvLog->from =$newTv;
|
|
}
|
|
$tvLog->save();
|
|
}
|
|
}
|