Laravel 5.4 Password Reset

2019-07-02 01:09发布

问题:

I have a Laravel 5.4 application and I have a view in my admin area that allows me to see all users.

I want to create a function that allows me to click a button in the back end that automates the process of sending the default Laravel password reset functionality.

In my view I have the following:

<table class="table table-hover">
                        <thead>
                            <th>#</th>
                            <th>Company</th>
                            <th>Name</th>
                            <th>Email Address</th>
                            <th>Action</th>
                        </thead>
                        <tbody>
                            @foreach(\App\User::all() as $c)
                                <tr>
                                    <td>{{ $c->id }}</td>
                                    <td>{{ $c->company->company_name }}</td>
                                    <td>{{ $c->name }}</td>
                                    <td>{{ $c->email }}</td>
                                    <td><a href="/admin/user/{{ $c->id }}/password/reset">Password Reset</a></td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>

On the link click for resetting the password this currently via my routes hits the following function

public function passwordReset($id)
    {

        $user = User::FindOrFail($id);

        Password::sendResetLink($user->email);

    }

I'm not to familiar with Laravels default password reset functionality so I'm probably way off but I get the following error:

Argument 1 passed to Illuminate\Auth\Passwords\PasswordBroker::sendResetLink() must be of the type array, string given,

回答1:

You need to send an array with email as key:

Password::sendResetLink(['email' => $user->email]);