【问题标题】:i am working on application and i got this notify() error我正在处理应用程序,我收到了这个 notify() 错误
【发布时间】:2019-04-13 20:29:33
【问题描述】:

*在 null 时调用成员函数 notify()? *Symfony \ Component \ Debug \ Exception \ 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');
}

【问题讨论】:

  • 看起来$user 为空。 User::where('id','=','1') 不应该使用$student_id 吗?
  • 很抱歉,请您说明一下要删除的内容和添加的内容,谢谢 nigel
  • 试试$user = User::where('id','=',$student_id)->first();
  • 您没有将 student_id 放在 session 中显示的代码中的任何位置...您在哪里制作 session(['student_id' => $request->input('student_id')]);
  • 请努力改进你的代码风格,这样读起来很难。

标签: php laravel


【解决方案1】:

在您的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
}

【讨论】:

  • 谢谢兄弟......但它给了我新的错误,即:语法错误,意外的'auth'(T_STRING),期待','或')'在行 - >返回视图('auth .studentregistration4');
  • 不,但我正在尝试解决我真的不知道语法有什么问题
  • @HassanAli 您的视图已存储且此名称正确resources/views/auth/studentregistration4.blade.php?
  • 是的,它存在没有问题...我如何声明 notfy 函数的语法问题:$user->notify(new registration_details(您的申请号是:-'$student_id' ));我从编辑那里知道..当单词应该轻巧时
猜你喜欢
  • 2021-08-26
  • 2021-10-04
  • 1970-01-01
  • 2022-08-15
  • 2016-12-28
  • 2022-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多