如何在Laravel 5.2中手动发送密码重置请求? [英] How do I manually send a password reset request in Laravel 5.2?

查看:233
本文介绍了如何在Laravel 5.2中手动发送密码重置请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从控制器内部手动将密码重置请求发送给特定用户(不是当前登录的用户)。我在Laravel代码中进行了一些挖掘,似乎应该在 ResetsPasswords postEmail(Request $ request) >,但我似乎无法弄清楚如何访问正确的 PasswordController 实例来调用它。

I would like to manually send a password reset request to a specific user (not the one currently logged in) from within a controller. I did some digging around in the Laravel code and it seems like I should be calling postEmail(Request $request) in ResetsPasswords, but I can't seem to figure out how to get access to the right PasswordController instance to call it.

推荐答案

为什么不为您的控制器提供类似的功能?

Why not just something like this for your controller:

<?php

namespace Illuminate\Foundation\Auth;

use Illuminate\Http\Request;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Password;

class YourController extends Controller
{
    public function sendEmail()
    {
        $credentials = ['email' => $email_address];
        $response = Password::sendResetLink($credentials, function (Message $message) {
            $message->subject($this->getEmailSubject());
        });

        switch ($response) {
            case Password::RESET_LINK_SENT:
                return redirect()->back()->with('status', trans($response));
            case Password::INVALID_USER:
                return redirect()->back()->withErrors(['email' => trans($response)]);
        }
    }
}

您并没有真正解释您要如何发送此消息的上下文,请相应调整。

You don't really explain the context of how you want to send this, so adjust accordingly.

这篇关于如何在Laravel 5.2中手动发送密码重置请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆