Skip to content

Commit

Permalink
finally fixed the validation rule
Browse files Browse the repository at this point in the history
  • Loading branch information
giddy77 committed Oct 23, 2023
1 parent 4f90155 commit f1cb437
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/Rules/Uppercase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
namespace App\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Contracts\Validation\Rule;

class Uppercase implements ValidationRule
class Uppercase implements Rule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
public function passes($attribute, $value)
{
if (ucfirst($value) !== $value) {
$fail("The $attribute must start with an uppercase letter.");
if (empty($value)) {
return false;
}

$firstCharacter = $value[0];
return $firstCharacter === strtoupper($firstCharacter);
}

public function message()
{
return 'The title does not start with an uppercased letter';
}
}

0 comments on commit f1cb437

Please sign in to comment.