$request->validate([
'email' =>'required|exists:users',
'password'=>'required|password'
]);
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppRulesMatchOldPassword;
use IlluminateSupportFacadesHash;
use AppUser;
class ChangePasswordController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return IlluminateContractsSupportRenderable
*/
public function index()
{
return view('changePassword');
}
/**
* Show the application dashboard.
*
* @return IlluminateContractsSupportRenderable
*/
public function store(Request $request)
{
$request->validate([
'current_password' => ['required', new MatchOldPassword],
'new_password' => ['required'],
'new_confirm_password' => ['same:new_password'],
]);
User::find(auth()->user()->id)->update(['password'=> Hash::make($request->new_password)]);
dd('Password change successfully.');
}
}
<?php
namespace AppRules;
use IlluminateContractsValidationRule;
use IlluminateSupportFacadesHash;
class MatchOldPassword implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return Hash::check($value, auth()->user()->password);
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'The :attribute is match with old password.';
}
}
Code Example |
---|
Php :: |
Php :: |
:: what is cors in laravel |
:: WordPress Plugin Definition |
Php :: |
Php :: |
Php :: license_verify |
:: |
Php :: laravel migration text length |
Php :: limit query codeiniter 3 |
Php :: php variable inside mysql query |
Php :: explode (PHP 4, PHP 5, PHP 7, PHP 8) explode — Split a string by a string |
:: in php how to check md5 password |
Php :: |
Php :: |
:: |
:: |
Php :: |
Php :: |
Php :: get custom field post wordpress dev |
Php :: php sec to hours/minuts |
Php :: install pdo mysql in alpine-apache php 5.6 |
Php :: |
:: PDO::ATTR_EMULATE_PREPARES = true Security issue |
Php :: |
Php :: laravel casts pivot table |
Php :: |
:: |
:: |
Php :: php get error |