2016-07-26 01:39:30 -07:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-07-26 01:39:30 -07:00
|
|
|
namespace App\Http\Traits;
|
|
|
|
|
|
|
|
trait UniqueUndeletedTrait
|
|
|
|
{
|
|
|
|
/**
|
2021-06-10 13:15:52 -07:00
|
|
|
* Prepare a unique_ids rule, adding a model identifier if required.
|
|
|
|
*
|
|
|
|
* @param array $parameters
|
|
|
|
* @param string $field
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-07-26 01:39:30 -07:00
|
|
|
protected function prepareUniqueUndeletedRule($parameters, $field)
|
|
|
|
{
|
|
|
|
// Only perform a replacement if the model has been persisted.
|
|
|
|
if ($this->exists) {
|
2021-06-10 13:15:52 -07:00
|
|
|
return 'unique_undeleted:'.$this->table.','.$this->getKey();
|
2016-07-26 01:39:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 'unique_undeleted:'.$this->table.',0';
|
|
|
|
}
|
|
|
|
}
|