2

Working on Laravel 7 Project. Required to reset password for multiuser (Admin,supervisor,student). Posting my code below. Password reset email link is working fine, but when i try to change my password it gives me error with email. I tried finding its root but couldn't find it. Request help..

Thanks in advance.. Posting necessory files below.. if require more, please tell me.

AdminForgetPasswordController

 <?php
  namespace App\Http\Controllers\Admin\Auth;

    use App\Http\Controllers\Controller;
    use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
    use Password;
    class AdminForgotPasswordController extends Controller
{
public function __construct()
{
$this->middleware('guest:admin');
}
  /*
  |--------------------------------------------------------------------------
  | 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;

protected function broker()
{
    return Password::broker('admins');
}

public function showLinkRequestForm()
{   
    return view('auth.passwords.admin-email');
}
}

AdminResetPasswordController

<?php

  namespace App\Http\Controllers\Admin\Auth;

  use App\Http\Controllers\Controller;
  use App\Providers\RouteServiceProvider;
  use Illuminate\Foundation\Auth\ResetsPasswords;
  use Auth;
  use Password;
  use Illuminate\Http\Request;
  class AdminResetPasswordController extends Controller
  {

   /*
   |--------------------------------------------------------------------------
   | Password Reset Controller
   |--------------------------------------------------------------------------
   |
   | This controller is responsible for handling password reset requests
   | and uses a simple trait to include this behavior. You're free to
   | explore this trait and override any methods you wish to tweak.
   |
  */

  use ResetsPasswords;



  /**
   * Where to redirect users after resetting their password.
   *
   * @var string
   */
 protected $redirectTo = '/admin/home';
 public function __construct()
 {
  $this->middleware('guest:admin');
 }
 protected function broker()
 {
    return Password::broker('admin');
 }
 public function showResetForm(Request $request, $token = null)
 {   
     return view('auth.passwords.admin-reset')->with(
     ['token' => $token, 'email' => $request->email]);
 }
 }

Admin Model

<?php

  namespace App\Model\admin;

  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Foundation\Auth\User as Authenticatable;
  use Illuminate\Notifications\Notifiable;
  use App\Notifications\AdminResetPasswordNotification;
  use Illuminate\Auth\Passwords\CanResetPassword;
  class Admin extends Authenticatable 
  {
    use Notifiable;
    protected $guard = 'admin';

   /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  protected $fillable = [
     'name', 'email', 'password',
  ];

   /**
   * The attributes that should be hidden for arrays.
   *
   * @var array
   */
  protected $hidden = [
     'password', 'remember_token',
   ];
  public function sendPasswordResetNotification($token)
  {
     $this->notify(new AdminResetPasswordNotification($token));
  }
  }

AdminResetPasswordNotification

<?php

   namespace App\Notifications;

   use Illuminate\Bus\Queueable;
   use Illuminate\Contracts\Queue\ShouldQueue;
   use Illuminate\Notifications\Messages\MailMessage;
   use Illuminate\Notifications\Notification;

class AdminResetPasswordNotification extends Notification
{
  use Queueable;
  public $token;

 /**
  * Create a new notification instance.
  *
  * @return void
  */
  public function __construct($token)
  {
     $this->token=$token;
  }

 /**
  * Get the notification's delivery channels.
  *
  * @param  mixed  $notifiable
  * @return array
  */
 public function via($notifiable)
 {
     return ['mail'];
 }

 /**
  * Get the mail representation of the notification.
  *
  * @param  mixed  $notifiable
  * @return \Illuminate\Notifications\Messages\MailMessage
  */
 public function toMail($notifiable)
 {
     return (new MailMessage)
                ->line('You are receiving this email because we received a password reset request for your account.')
                ->action('Reset Password', route('admin.password.reset', $this->token))
                ->line('If you did not request a password reset, no further action is required.');
}

 /**
  * Get the array representation of the notification.
  *
  * @param  mixed  $notifiable
  * @return array
  */
 public function toArray($notifiable)
 {
    return [
        //
    ];
 }
  }

Resources/views/Auth/password/admin-email.blade.php

@extends('layouts.app')

@section('content')
 <div class="container">
   <div class="row justify-content-center">
     <div class="col-md-8">
        <div class="card">
            <div class="card-header">{{ __('Admin Reset Password') }}</div>

            <div class="card-body">
                @if (session('status'))
                    <div class="alert alert-success" role="alert">
                        {{ session('status') }}
                    </div>
                @endif

                <form method="POST" action="{{ route('admin.password.email') }}">
                    @csrf

                    <div class="form-group row">
                        <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                        <div class="col-md-6">
                            <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>

                            @error('email')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="form-group row mb-0">
                        <div class="col-md-6 offset-md-4">
                            <button type="submit" class="btn btn-primary">
                                {{ __('Send Password Reset Link') }}
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</div>
           @endsection

resources/views/auth/password/admin-reset.blade.php

@extends('layouts.app')

@section('content')
 <div class="container">
   <div class="row justify-content-center">
     <div class="col-md-8">
        <div class="card">
            <div class="card-header">{{ __('Reset Password') }}</div>

              <div class="card-body">
                <form method="POST" action="{{ route('password.update') }}">
                    @csrf

                    <input type="hidden" name="token" value="{{ $token }}">

                     <div class="form-group row">
                        <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                         <div class="col-md-6">
                            <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ $email ?? old('email') }}" required autocomplete="email" autofocus>

                            @error('email')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="form-group row">
                        <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                        <div class="col-md-6">
                            <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="new-password">

                            @error('password')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="form-group row">
                        <label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

                        <div class="col-md-6">
                            <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
                        </div>
                    </div>

                    <div class="form-group row mb-0">
                        <div class="col-md-6 offset-md-4">
                            <button type="submit" class="btn btn-primary">
                                {{ __('Reset Password') }}
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
  </div>
</div>
@endsection

0 Answers0