• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation Placeholders being ignored for is_unique


PHP Code:
protected $validationRules = [
   'email' => 'required|valid_email|is_unique[users.email,id,{id}]'

looking at the is_unique method in Rules.php it does not appear {id} is being converted to it's corresponding value in $data.


Something like this?

PHP Code:
    public function is_unique(string $str nullstring $field, array $data): bool
// Grab any data for exclusion of a single row.
list($field$ignoreField$ignoreValue) = array_pad(explode(','$field), 3null);

// Break the table and field apart

$db Database::connect();
$row $db->table($table)

        if ( ! empty(
$ignoreField) && ! empty($ignoreValue))
            if (
$ignoreValue[0] == '{') {
$key substr($ignoreValue1, -1);
                if (isset(
$ignoreValue $data[$key];
$row $row->where("{$ignoreField} !="$ignoreValue);

        return (bool) (
getRow() === null);

Any updates on this? This comes in to play when post data needs validating and you call a validation rule set by name... instead of by array... so you can't actually pass {$id}:


The is_unique rule does not check for post data... it only looks if the value was passed in the check.

Look at my example to see how I worked around this... but I'm not sure if there is a better way?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.