php - 我正在处理应用程序,我收到了这个 notify() 错误
问题描述
* 在 null 上调用成员函数 notify()?*Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) 调用成员函数notify() on null
*控制器\用户控制器.php
public function store3(Request $request)
{
$request->session()->flush();
return redirect('home');
}
public function check(Request $request)
{
$request->validate( [ ' => 'required|string|max:255', ]);
$student_id = $request->input('student_id');
$query = DB::select("SELECT * FROM `users` WHERE `student_id` =
'$student_id'") ;
return view('auth.studentregistraionStatus',['query'=>$query]);
}
public function notificationmail(Request $request)
{
$student_id = session('student_id');
$user = User::where('id','=','1')->first();
$user->notify(new registration_details("Your application number is :- $student_id" ));
return view('auth.studentregistration4');
}
解决方案
在您的users
表中, theid
被声明为 aninteger
但在您的where
子句中您正在传递一个字符串。
尝试改变这个:
...
->where('id', '=', '1')
->first();
...
对此:
...
->where('id', '=', 1)
->first();
...
当然,要使其动态化,请替换1
为类似的变量$user_id
此外,在通知用户之前,请确保您确实有一个用户对象:
$user = // get your user
if ( ! is_null($user))
{
// Make the notification
}