Files
exchange-2.0/app/Classes/Modules/Accounts/Services/ChangesPassword.php
T
omair saleh 05401f6bbc large commit
2021-03-11 13:06:40 +08:00

32 lines
788 B
PHP

<?php
namespace App\Classes\Modules\Accounts\Services;
use App\Classes\Exceptions\InternalServerErrorException;
use App\Classes\Modules\Accounts\DataTransferObjects\NewPasswordObject;
use App\Models\User;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Hash;
class ChangesPassword
{
/**
* @param User $user
* @param NewPasswordObject $object
* @return bool
* @throws InternalServerErrorException
*/
public function execute(User $user, NewPasswordObject $object): bool {
try {
$user->password = Hash::make($object->getPassword());
return $user->save();
} catch (QueryException $exception){
throw new InternalServerErrorException($exception->getMessage());
}
}
}