簡體   English   中英

Laravel 5.2密碼重置返回致命錯誤:“在null上調用成員函數getEmailForPasswordReset()”

[英]Laravel 5.2 password reset returns the fatal error: “Call to a member function getEmailForPasswordReset() on null”

一個非常相似的問題 ,但我無法對此發表評論或遵循提問作者的建議來解決我的問題。

密碼重置已經設置並運行,我回到它檢查翻譯字符串,並開始收到此錯誤: Fatal error: Call to a member function getEmailForPasswordReset() on null (View: /home/vagrant/code/ecc/resources/views/emails/password.blade.php)

我沒有為項目使用源代碼控制,所以我無法確定它何時停止工作。 我在密碼控制器中更改的唯一內容是getSendResetLinkEmailSuccessResponse()getSendResetLinkEmailFailureResponse()以AJAX化我的表單。 幾乎完全相同的代碼在另一個項目中運行,但在相同的Homestead上運行。 我檢查了整個調用鏈,毫不奇怪,它沒有任何問題 - 在視圖渲染過程中,用戶對象在某處變為null:

8. at Mailer->getView('emails.password', array('token' => 'd81d3190958330e2a4e0552db07a1efc80d1768eddde0447f8efb9e588719ff4', 'user' => object(User), 'message' => object(Message))) in Mailer.php line 323

4. at CompilerEngine->get('/home/vagrant/code/ecc/resources/views/emails/password.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'token' => 'd81d3190958330e2a4e0552db07a1efc80d1768eddde0447f8efb9e588719ff4', 'user' => null, 'message' => object(Message), 'locale' => 'en')) in View.php line 149

3. at PhpEngine->evaluatePath('/home/vagrant/code/ecc/storage/framework/views/469f1ba57eac0cc812c6c63e33641df67f64c100.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'token' => 'd81d3190958330e2a4e0552db07a1efc80d1768eddde0447f8efb9e588719ff4', 'user' => null, 'message' => object(Message), 'locale' => 'en')) in CompilerEngine.php line 59

因此,Mailer將用戶作為檢索對象獲取,但在視圖呈現期間它變為null。 我嘗試重新安裝所有東西, vagrant destroydump-autoloadclear-compiled ,刪除所有已編譯的視圖,我也沒有使用Laravel Auto Presenter,或類似的任何試圖在裝飾器中傳遞用戶模型時將其自動換行視圖。

你能告訴一下嗎? 謝謝!

編輯:這是我的控制器,按要求:

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;

class PasswordController extends Controller
{
    use ResetsPasswords;


    protected $subject;

    protected $redirectTo = '/';

    /**
     * Create a new password controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');

        $this->subject = trans('emails.password_reset.subject');
    }

    /**
     * Display the password reset view for the given token.
     *
     * If no token is present, display the link request form.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  string|null  $token
     * @return \Illuminate\Http\Response
     */
    public function showResetForm($request, $token = null)
    {
        if (is_null($token)) {
            abort(403, 'Unauthorized action.');
        }

        $email = $request->input('email');

        return view('reset')->with(compact('token', 'email'));
    }

    /**
     * Get the response for after the reset link has been successfully sent.
     *
     * @param  string  $response
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function getSendResetLinkEmailSuccessResponse($response)
    {
        return response()->json([
            'success' => true,
        ]);
    }

    /**
     * Get the response for after the reset link could not be sent.
     *
     * @param  string  $response
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function getSendResetLinkEmailFailureResponse($response)
    {
        return response()->json([
            'success' => false,
        ]);
    }
}

我使用視圖編寫器類將幾個變量附加到所有視圖,其中一個是存儲Auth::user() $user 毋庸置疑,這個變量顯然是空的,因為用戶在密碼重置期間返回時沒有登錄 - 覆蓋了Mailer在鏈中進一步傳遞的$user變量。

解決方案是在視圖編輯器中重命名$ user變量,使用自定義密碼代理覆蓋emailResetLink()並在那里更改變量名稱,或者在ComposerServiceProvider中傳遞特定視圖的數組,而不是作為通配符傳遞“*” 。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM