Skip to content

Instantly share code, notes, and snippets.

@Artistan Artistan/Extend.php
Created Aug 22, 2018

Embed
What would you like to do?
Laravel 5.6 Password does/not contain login name
<?php
namespace App;
use Illuminate\Support\Facades\Input;
use Illuminate\Validation\Validator;
/**
* Class Extend
*/
class Extend
{
/**
* @example
* Validator::extend('not_contains', 'App\Extend@not_contains');
*
* -- add rule to attribute validation,
* -- in this case it checks if the 'login' Input is NOT in the password value
* 'password' => [ ...
* 'not_contains:login',
* ]
* /example
* @param string $attribute
* @param mixed $value
* @param mixed $parameters
* @param Validator $validator
* @return bool
*/
public function not_contains($attribute, $value, $parameters, Validator $validator)
{
if(self::require_parameters($parameters,1) && $attribute_value = Input::get($parameters[0])){
return strpos(strtoupper($value), strtoupper($attribute_value))===false?true:false;
}
return false;
}
/**
* @example
* Validator::extend('contains', 'App\Extend@contains');
*
* -- add rule to attribute validation,
* -- in this case it checks if the 'login' Input is in the password value
* 'password' => [ ...
* 'contains:login',
* ]
* /example
* @param string $attribute
* @param mixed $value
* @param mixed $parameters
* @param Validator $validator
* @return bool
*/
public function contains($attribute, $value, $parameters, Validator $validator)
{
if(self::require_parameters($parameters,1) && $attribute_value = Input::get($parameters[0])){
return strpos(strtoupper($value), strtoupper($attribute_value))===false?false:true;
}
return false;
}
private static function require_parameters($parameters,$count) {
return count($parameters) === $count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.