![](/img/trans.png)
[英]Fatal error: Call to a member function query() on null (Laravel 5.2)
[英]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 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,
]);
}
}
我使用视图编写器类将几个变量附加到所有视图,其中一个是存储Auth::user()
$user
。 毋庸置疑,这个变量显然是空的,因为用户在密码重置期间返回时没有登录 - 覆盖了Mailer在链中进一步传递的$user
变量。
解决方案是在视图编辑器中重命名$ user变量,使用自定义密码代理覆盖emailResetLink()
并在那里更改变量名称,或者在ComposerServiceProvider中传递特定视图的数组,而不是作为通配符传递“*” 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.