亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

類 RedirectIfPasswordNotUpdated 不存在

類 RedirectIfPasswordNotUpdated 不存在

PHP
慕斯709654 2021-10-15 16:06:11
我使用以下命令創建了一個自定義中間件php artisan make:middleware RedirectIfPasswordNotUpdated這是我的中間件<?phpnamespace App\Http\Middleware;use Closure;use Carbon\Carbon;use Illuminate\Support\Facades\Auth;use App;class RedirectIfPasswordNotUpdated{    public function handle($request, Closure $next)    {        if (!App::environment(['production'])) {            return $next($request);        }        $user = Auth::user();        if (!$user->password_updated_at) {            return redirect()->route('profile.password.edit')->with([                'message' => 'Please update your password to proceed',                'alertType' => 'warning',            ]);        }        if (Carbon::now()->diffInDays(Carbon::parse($user->password_updated_at)) > 90) {            return redirect()->route('profile.password.edit')->with([                'message' => 'Your password has expired! Please update your password to proceed',                'alertType' => 'warning',            ]);        }        return $next($request);    }}我想在我的控制器的構造函數中使用這個中間件,如下所示public function __construct(){    $this->middleware('auth');    $this->middleware('RedirectIfPasswordNotUpdated');}當,我這樣做時,我得到一個ReflectionException (-1)說Class RedirectIfPasswordNotUpdated does not exist我在其他 Laravel(v5.4、v5.6)項目中以相同的方式使用這個中間件,并且沒有任何問題。但它在當前版本 (v5.8) 中不起作用。我究竟做錯了什么?
查看完整描述

1 回答

?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

正如我所看到的,您尚未注冊您middleware class的app\Http\Kernel.php. 注冊一個中間件非常簡單,如下所示:


protected $routeMiddleware = [

   'middle_name' => \App\Http\Middleware\RedirectIfPasswordNotUpdated::class,

]


查看完整回答
反對 回復 2021-10-15
  • 1 回答
  • 0 關注
  • 132 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號