有a very similar question,但我无法对此发表评论,也无法按照提问作者的建议来解决我的问题。
密码重置已经设置并运行,我回到它检查翻译字符串,并开始收到此错误: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,
]);
}
}
答案 0 :(得分:0)
我使用view composer类将几个变量附加到所有视图,其中一个变量$user
存储Auth::user()
。毋庸置疑,这个变量显然是空的,因为用户在密码重置期间返回时没有登录 - 覆盖了Mailer在链中进一步传递的$user
变量。
解决方案是在视图编辑器中重命名$ user变量,使用自定义密码代理覆盖emailResetLink()
并在那里更改变量名称,或者在ComposerServiceProvider中传递特定视图的数组,而不是“ *“作为通配符。