Skip to content

Instantly share code, notes, and snippets.

@sunshain
Created April 21, 2016 18:57
Show Gist options
  • Save sunshain/3de41ae2bc112c32aa72b1e953039c6b to your computer and use it in GitHub Desktop.
Save sunshain/3de41ae2bc112c32aa72b1e953039c6b to your computer and use it in GitHub Desktop.
<?php
/*
* add to config/app.php providers
* App\Providers\ValidationProvider::class,
*
* add to lang/validation.php
* 'currented' => 'The current password is not correct.',
*/
namespace App\Providers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
class ValidationProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Validator::extend('currented',
function($attribute, $value, $parameters, $validator) {
return Hash::check($value, Auth::user()->password);
}
);
Validator::replacer('currented',
function($message, $attribute, $rule, $parameters) {
return str_replace(':values', implode(', ', $parameters), $message);
}
);
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
@Siebov
Copy link

Siebov commented Apr 21, 2016

окей, а как теперь это вызывать внутри валидатора?

@sunshain
Copy link
Author

currented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment