2021-10-08 13:19:16 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Traits;
|
|
|
|
|
|
|
|
trait TwoColumnUniqueUndeletedTrait
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Prepare a unique_ids rule, adding a model identifier if required.
|
|
|
|
*
|
|
|
|
* @param array $parameters
|
|
|
|
* @param string $field
|
|
|
|
* @return string
|
|
|
|
*/
|
2024-08-16 14:45:57 -07:00
|
|
|
protected function prepareTwoColumnUniqueUndeletedRule($parameters)
|
2021-10-08 13:19:16 -07:00
|
|
|
{
|
|
|
|
$column = $parameters[0];
|
|
|
|
$value = $this->{$parameters[0]};
|
|
|
|
|
2024-08-16 16:27:44 -07:00
|
|
|
// This is an existing model we're updating so ignore the current ID ($this->getKey())
|
2021-10-08 13:19:16 -07:00
|
|
|
if ($this->exists) {
|
|
|
|
return 'two_column_unique_undeleted:'.$this->table.','.$this->getKey().','.$column.','.$value;
|
|
|
|
}
|
|
|
|
|
2024-08-16 16:27:44 -07:00
|
|
|
// This is a new record, so we can ignore the current ID
|
2021-10-08 13:19:16 -07:00
|
|
|
return 'two_column_unique_undeleted:'.$this->table.',0,'.$column.','.$value;
|
|
|
|
}
|
|
|
|
}
|