但是我不想通知任何经过身份验证的用户,我需要通知询问问题的人,这就是为什么我尝试传递 $ asker ... 所以,如果您知道如何解决此问题,请告诉我... 我真的很感谢你们的任何想法或建议.谢谢.刀片: < form action =" {{route('questions.answers',['question'=> $ show-> id,'asker'==> $ show->用户-> id])}}"方法=POST"enctype ="multipart/form-data".@csrf< div class ="mb-4">< textarea name =" answer"id ="answer"class ="form-control BSinaBold"行="7"占位符=写下答案"</textarea>@error('answer')< div class ="text-red-500 mt-2 text-sm">{{$ message}}</div>@enderror</div></br>< button type =提交";class ="btn btn-primary">发送"/按钮";</form> 解决方案问题是 asker 只是一个ID,您应该获取 asker 的其他信息从用户表中,然后将您的通知传递给 asker . $ asker =用户:: findOrFail($ asker);$ asker-> notify(new RepliedToThread($ question)); I'm working with Laravel 8 to make a forum and now I wanted to send a notification to a user who has asked a question whenever someone answered that question.So in order to do that, I added this to the Controller:public function postAnswer(Request $request, $question, $asker) { $validate_data = $request->validate([ 'answer' => 'required', ]); $answer = Answer::create([ 'answer' => $request->answer, 'user_id' => auth()->user()->id, 'question_id' => $question, ]); $asker->notify(new RepliedToThread($question)); return back(); }So the $question is the question id and $asker is the user id of the person who has asked the question.But now I get this error:Call to a member function notify() on stringNow the interesting part is that, when I use auth()->user()->notify(new RepliedToThread($question));, it is working fine!But I don't want to notify any authenticated user, I need to notify the person who has asked question, that's why I tried passding $asker...So if you know how to solve this question, please let me know...I would really appreciate any idea or suggestion from you guys.Thanks in advance.Blade:<form action="{{ route('questions.answers', ['question' => $show->id, 'asker' => $show->user->id]) }}" method="POST" enctype="multipart/form-data"> @csrf <div class="mb-4"> <textarea name="answer" id="answer" class="form-control BSinaBold" rows="7" placeholder="Write down answer"></textarea> @error('answer') <div class="text-red-500 mt-2 text-sm"> {{ $message }} </div> @enderror </div> </br> <button type="submit" class="btn btn-primary">Send</button></form> 解决方案 The problem is that asker is just an id, you should take the other information of the asker from the user table and after that pass your notification to the asker.$asker = User::findOrFail($asker);$asker->notify(new RepliedToThread($question)); 这篇关于Laravel 8:在字符串上调用成员函数notify()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 03:41