朋友们,我已经修改了密码重置表列名'created_at'而不是'created'。如果我在迁移时更改列名“已创建”,但我收到的错误列未找到'created_at'。
\vendor\laravel\framework\src\Illuminate\Auth\Passwords\DatabaseTokenRepository.php
protected function getPayload($email, $token)
{
return ['email' => $email, 'token' => $token, 'created_at' => new Carbon];
}
这是来自列名'created_at'的文件,我可以覆盖此功能请建议我..
答案 0 :(得分:2)
我想我已经找到了一种方法,可以在不触及供应商目录的情况下完成此操作。
适用于Laravel 5.2
Illuminate\Auth\Passwords\DatabaseTokenRepository
Illuminate\Auth\Passwords\PasswordBrokerManager
config/app.php
并从供应商数组中注释掉 PasswordResetServiceProvider 在您的应用服务提供商中注册第3步的密码经纪人管理器实例
$ this-> app-> singleton('auth.password',function($ app){ 返回新的YourPasswordBrokerManager($ app); });
$ this-> app-> bind('auth.password.broker',function($ app){ 返回$ app-> make('auth.password') - > broker(); });
对于Lravel 5
Illuminate\Auth\Passwords\DatabaseTokenRepository
Illuminate\Auth\Passwords\PasswordResetServiceProvider
config/app.php
并从供应商数组中注释掉 PasswordResetServiceProvider 请注意,我没有对此进行测试,但它应该适用于理论。
答案 1 :(得分:0)
已解决:我在我的 Laravel 5.4 项目中应用了 5.2 步骤:
ForgotPasswordHelperRepository.php
<?PHP
namespace App\Helpers;
use Carbon\Carbon;
class ForgotPasswordHelperRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRepository
{
/**
* Build the record payload for the table.
* I wanted to add an extra column organization_id
* organizationId() is a helper method I created
* @param string $email
* @param string $token
* @return array
*/
protected function getPayload($email, $token)
{
return ['email' => $email, 'token' => $this->hasher->make($token), 'created_at' => new Carbon,'organization_id' => organizationId()];
}
}
PasswordBrokerManagerHeler.php
<?PHP
namespace App\Helpers;
use Closure;
use Illuminate\Auth\Passwords\DatabaseTokenRepository;
use Illuminate\Auth\Passwords\PasswordBroker;
use Illuminate\Support\Str;
class PasswordBrokerManagerHelper extends \Illuminate\Auth\Passwords\PasswordBrokerManager
{
/**
* @inheritDoc
*/
public function sendResetLink(array $credentials)
{
// TODO: Implement sendResetLink() method.
}
/**
* @inheritDoc
*/
public function reset(array $credentials, Closure $callback)
{
// TODO: Implement reset() method.
}
/**
* @inheritDoc
*/
public function validator(Closure $callback)
{
// TODO: Implement validator() method.
}
/**
* @inheritDoc
*/
public function validateNewPassword(array $credentials)
{
// TODO: Implement validateNewPassword() method.
}
/**
* Resolve the given broker.
*
* @param string $name
* @return \Illuminate\Contracts\Auth\PasswordBroker
*
* @throws \InvalidArgumentException
*/
protected function resolve($name)
{
$config = $this->getConfig($name);
if (is_null($config)) {
throw new \InvalidArgumentException("Password resetter [{$name}] is not defined.");
}
// The password broker uses a token repository to validate tokens and send user
// password e-mails, as well as validating that password reset process as an
// aggregate service of sorts providing a convenient interface for resets.
return new PasswordBroker(
$this->createTokenRepository($config),
$this->app['auth']->createUserProvider($config['provider'])
);
}
protected function createTokenRepository(array $config)
{
$key = $this->app['config']['app.key'];
if (Str::startsWith($key, 'base64:')) {
$key = base64_decode(substr($key, 7));
}
$connection = isset($config['connection']) ? $config['connection'] : null;
// return new DatabaseTokenRepository(
return new ForgotPasswordHelperRepository(
$this->app['db']->connection($connection),
$this->app['hash'],
$config['table'],
$key,
$config['expire']
);
}
}
接下来,只需将以下内容复制并粘贴到 AppServiceProvider @ register 方法
$this->app->singleton('auth.password', function ($app) { return new PasswordBrokerManagerHelper($app); });
$this->app->bind('auth.password.broker', function ($app) { return $app->make('auth.password')->broker(); });