Files
2026-09-21 10:59:32 +01:00

58 lines
1.4 KiB
PHP
Executable File

<?php
namespace Modules\M3\Models;
use Illuminate\Database\Eloquent\Model;
class ShipTo extends Model
{
protected $table = 'ICM665M';
public $timestamps = false;
protected $primaryKey = ['AUSHSHZP', 'AUSHWHS'];
protected $uniqueKey = ['AUSHSHZP', 'AUSHWHS'];
public $incrementing = false;
protected $fillable = [
'AUSTCN',
'AUSHSHNM',
'AUSHSHA1',
'AUSHSHA2',
'AUSHSHCI',
'AUSHSHST',
'AUSHSHZP',
'AUSHSHCT',
'AUSHWHS',
];
public function save(array $options = [])
{
if ($this->validateUniqueComposite()) {
return parent::save($options);
} else {
return false;
// ->withErrors(['unique' => 'The combination of AUSHSHZP and AUSHWHS must be unique'])
// ->withInput();
}
}
protected function validateUniqueComposite()
{
$query = self::query();
// Check if the combination of AUSHSHZP and AUSHWHS already exists
$existingRecord = $query->where('AUSHSHZP', $this->AUSHSHZP)
->where('AUSHWHS', $this->AUSHWHS);
// If this is an existing record being updated, exclude itself from the check
if ($this->exists) {
$existingRecord->where($this->getKeyName(), '!=', $this->getKey());
}
return $existingRecord->count() === 0;
}
}