Created
November 4, 2016 01:46
-
-
Save kuroisuna/fc92e0fbd15c4073b6463d599f252eed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!function_exists('post_to_put')) { | |
/** | |
* Turns POST/STORE rules to PUT/PATCH/UPDATE ones | |
* | |
* @param array $rules Validation rules array | |
* @param string $ignore Value to ignore | |
* @param string $additional Additional where clauses | |
* | |
* @return array | |
*/ | |
function post_to_put($rules, $ignore = '', $additional = '') | |
{ | |
return array_map(function ($rule) use ($ignore, $additional) { | |
if ($ignore) { | |
$additional = $additional ? ",{$additional}" : ''; | |
$rule = preg_replace("/(unique:[\w,]+)/", "\$1,{$ignore}{$additional}", $rule); | |
} | |
$hasMention = str_contains($rule, "mention"); | |
if ($hasMention && $ignore) { | |
$rule = str_replace('mention', "mention:{$ignore}", $rule); | |
} | |
$rule = str_replace('required', 'filled', $rule); | |
return $rule; | |
}, $rules); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment