2016-06-07 40 views
1

a very similar question,但我無法評論它或按照問題作者的建議來解決我的問題。Laravel 5.2密碼重置返回致命錯誤:「調用成員函數getEmailForPasswordReset()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中運行。我查了通話的整個鏈條,勿庸置疑,沒有什麼不對的地方,用戶對象將變爲空時視圖渲染的地方:

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

因此,梅勒獲得一個用戶作爲一個retreived對象,但在視圖渲染過程中它變爲null。我嘗試重新安裝所有東西,vagrant destroy,dump-autoload,clear-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, 
     ]); 
    } 
} 
+0

請給出適當的格式,以便我們可以閱讀和回答 –

+0

變量$ user在視圖中使用,您在其上調用函數getEmailForPasswordReset()爲null(空/未設置)。全部在錯誤信息 –

+0

@VijayanandPremnath我應該改變或添加什麼來讓它更容易在你的眼睛上? – Banandrew

回答

0

我用view composer類的一對夫婦的變量追加到所有的意見,他們是$user存儲Auth::user()之一。不用說,這個變量顯然是空的,因爲用戶在密碼重置期間返回時沒有登錄 - 將覆蓋變量Mailer在鏈中進一步傳遞的$user變量。

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

相關問題