问题
auth.php
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'admins'=>[
'providers'=>'admins',
'table'=>'password_resets',
'expire'=>60,
'throttle'=>60,
],
],
AdminForgotPasswordController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Support\Facades\Password;
class AdminForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
public function __construct(){
$this->middleware('guest:admin');
}
/**
* Display the form to request a password reset link.
*
* @return \Illuminate\Http\Response
*/
public function showLinkRequestForm()
{
return view('auth.passwords.admin-email');
}
/**
* Get the broker to be used during password reset.
*
* @return \Illuminate\Contracts\Auth\PasswordBroker
*/
public function broker()
{
return Password::broker('admins');
}
}
problem is that i am making multiauth miniproject i code everything correct at user side and admin side...at user side is working well reset password notification is working well but when i go on admin panel and click on forgot password it shows me form to put email ,i put email and send reset link then this error appears what is problem anyone can know about that will be thankful.
回答1:
try this:
AdminForgotPasswordController.php
class AdminForgotPasswordController extends Controller
{
use SendsPasswordResetEmails;
protected function broker(){
return Password::broker('admins');
}
public function sendResetLinkEmail(Request $request){
$input = $request->all();
$rules = array(
'email' => "required",
);
$validator = Validator::make($input, $rules);
if ($validator->fails()) {
$arr = array("status" => 400, "message" => $validator->errors()->first());
} else {
// check if user already exists
$users = Admins::all();
if(!$users->isEmpty()){
foreach($users as $user){
if($user->email == $request['email']){
break;
}
$user = false;
}
}else{
$user = false;
}
if(!$user){
$arr = array("status" => 400, "message" => "That user doesn't exist");
return \Response::json($arr);
}
// create reset pass token
$token = Password::getRepository()->create($user);
$user->notify(new SendResetPasswordAdmin($token,$user->email));
$arr = array("status" => 200, "message" => "Email to reset password sent");
return \Response::json($arr);
}
}
}
And you need create SendResetPasswordAdmin on app/notifications whir this command php artisan make:notification SendResetPasswordAdmins
class SendResetPasswordAdmins extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($token,$email)
{
$this->token = $token;
$this->email = $email;
}
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
return (new MailMessage)
->line(Yourmessage)
->action('Message2', route('admins.password.reset', ['token' =>$this->token, 'email' => $this->email]))
->line(FooterMessage);
}
Route:
Route::get('admins/password/reset/{token}/{email}',
'ResetPasswordAdmins@showResetForm')->name('admins.password.reset');
And this:
class ResetPasswordAdmins extends Controller
{
public function showResetForm($token,$email){
return view(yourView)->with(['token' => $token, 'email'
=> $email]);
}
public function updatePass(Request $request){
//Here your logic and validator
}
回答2:
i found it solution.. Problem was in auth.php folder i was using providers instead of provider so this error appears. just check config/auth.php and replace this code.
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'admins'=>[
'provider'=>'admins',
'table'=>'password_resets',
'expire'=>60,
'throttle'=>60,
],
],
来源:https://stackoverflow.com/questions/60947038/argument-2-passed-to-illuminate-auth-passwords-passwordbroker-construct-mus