Skip to content

Commit

Permalink
Task 9. Your Own Validation Rule. Done
Browse files Browse the repository at this point in the history
  • Loading branch information
Teon54 committed Aug 4, 2024
1 parent 0801b84 commit 3d686ed
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/Rules/Uppercase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Str;

class Uppercase implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (Str::ucfirst($value) !== $value) {
$fail('The :attribute does not start with an uppercased letter');
}
}
}

0 comments on commit 3d686ed

Please sign in to comment.