Slug Validator
This validator can be used to ensure that the given value is a valid slug. If you don't know what a slug is, kindly read about it here
Usage
There are two different ways in which all Sparta validators can be used. See below examples for more explanations:
Example #1:
You can simply instantiate the Slug
validator and pass to it the data that you want to validate.
<?php
use Sparta\Validators\Slug;
$validator = Slug();
if(!$validator->isValid('This-is-Slug')){
//handle errors
}
Example #2:
You can build your validation rules and pass it to the Validation object to handle as shown below:
<?php
use Sparta\Validation;
$rules = [
'articleSlug' => 'slug',
];
//Assuming that your $data has an element with the key "title_slug"
$validation = new Validation($data, $rules);
if(!$validation->isValid()){
//handle errors
}
In case of validation failure, error messages can be retrieved using the getErrors
method.