我正在处理应用程序,但出现此notify()错误

时间:2018-11-10 14:11:30

标签: php laravel

  

*对成员函数notify()的调用是否为null?   * Symfony \组件\调试\异常\ FatalThrowableError(E_ERROR)   在null上调用成员函数notify()

* Controllers \ UserController.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');
}

1 个答案:

答案 0 :(得分:0)

users表中,id被声明为integer,但是在where子句中,您正在传递字符串。

尝试更改此内容:

...
->where('id', '=', '1')
->first();
...

对此:

...
->where('id', '=', 1)
->first();
...

当然,要使其动态化,请将1替换为$user_id之类的变量

此外,在通知用户之前,请确保您确实具有用户对象:

$user = // get your user
if ( ! is_null($user))
{
    // Make the notification
}