the smart password hashing and confirmation fields auto purge methods.

The first is very easy and intuitive:

private function smartPasswordHashing()
{
  if($this->attributes['password'])
    $this->attributes['password'] = Hash::make($this- >attributes['password']);
}

If a 'password' field is present, hash it. Nothing more!

Even if, it’s a little longer, the purgeConfirmationFields() isn’t so hard to understand:

private function purgeConfirmationFields()
{
  foreach($this->attributes as $name => $value)
  {
    if(Str::endsWith($name, '_confirmation'))
      unset($this->attributes[$name]);
  }
}

This time, I used the Str string utility class in order to use the endsWith() method, which is used to determine if a strings ends with a certain sequence of characters. Every '_confirmation' field is removed.

Advertisements