我的网站目前有一个奇怪的错误,只能在实时版本上显示,但不能在我的本地设置上显示。
基本上,在这种情况下,用户试图向艺术家(另一种类型的用户)询问引用,因此requestQuote
函数。
public function requestQuote(Request $request, AppMailer $mailer) {
$reciUsername = $request->input('recipient');
$recipientID = User::where('username', $reciUsername)->value('id');
$recipient = User::where('username', $reciUsername)->first();
$active_commissions_count = Commission::where('artist_id', $recipientID)
->where('complete', 0)
->where('stripe_charge_id', '!=', "")
->where('stripe_charge_id', '!=', null)
->count();
$this->validate($request, [
'message' => 'required|max:5000|min:10',
]);
$message = Auth::user()->messages()->create([
'body' => $request->input('message'),
'subject' => 'Status: Commission requested!',
'recipient_id' => $recipientID,
'sender_read' => 1,
'is_quote' => 1,
'quote_expires' => Carbon\Carbon::now()->addWeeks(1),
]);
$from = Auth::user()->username;
$mailer->sendQuoteRequestEmailTo($recipient, $from);
Auth::user()->update([
'timeout' => Carbon\Carbon::now(),
]);
dd("Message ID: " . $message->id . " - Message User ID: " . $message->user_id);
return redirect()->back()->with('info', 'Quote sent.');
}
这会创建一个艺术家可以阅读的消息。在这种情况下,recipient_id
用户是艺术家,user_id
用户是制作原始报价的用户。在此交易期间,这不应该在任何时候改变。
你会注意到那里有一个死刑。
在这种情况下,dd返回
" QUOTE REQUEST - 消息ID:30 - 消息用户ID:2 - 收件人ID:21"
大。到目前为止一切正常,并且正确的消息被发送,正确的用户被显示为已发送报价。
当艺术家回复报价时会出现问题。
public function quoteReply(Request $request, $messageId, AppMailer $mailer) {
$this->validate($request, [
"reply-{$messageId}" => 'max:5000',
"price" => 'required|min:10|max:9999|numeric',
"date" => 'required|date',
], [
'max' => 'The text body has a maximum of 5000 characters.',
'price.max' => 'Commissions have a maximum of 9999 US dollars.',
'price.min' => 'Commissions have a minimum of 10 US dollars.',
]);
$message = Message::notReply()->find($messageId);
if (!$message) {
return redirect()->route('home')->with('info', 'Something went wrong.');
}
$date = $request->input('date');
$date2 = DateTime::createFromFormat('m/d/Y', $date);
$date3 = $date2->format("Y-m-d");
$reply = message::create([
'body' => $request->input("reply-{$messageId}"),
'sender_read' => 3,
'reci_read' => 3,
])->user()->associate(Auth::user());
Message::where('id', $messageId)->update([
'updated_at' => Carbon\Carbon::now(),
'subject' => 'Status: Price quote delivered.',
'quoted' => 1,
'price' => $request->input('price'),
'estimated_date' => $date3,
'quote_expires' => Carbon\Carbon::now()->addWeeks(1),
]);
$userID = $message->value('user_id');
$recipientID = $message->value('recipient_id');
$user = User::where('id', $userID)->first();
if (Auth::user()->id == $userID) {
Message::where('id', $messageId)->update(['reci_read' => 0]);
}
if (Auth::user()->id == $recipientID) {
Message::where('id', $messageId)->update(['sender_read' => 0]);
}
$message->replies()->save($reply);
$from = Auth::user()->username;
$mailer->sendQuoteReplyEmailTo($user, $from);
dd("QUOTE REPLY - Message ID: " . $message->id . " - Message User ID: " . $message->user_id . " - Message Recipient ID: " . $message->recipient_id . " - User ID: " . $user->id );
return redirect()->back()->with('info', 'Price quote delivered.');
}
这将返回:
" QUOTE REPLY - 消息ID:30 - 消息用户ID:2 - 消息收件人 ID:21 - 用户ID:3"
当错误的用户收到电子邮件时,我首先注意到了这个问题。事实上,它始终是同一个用户收到电子邮件。用户3.如果我为艺术家使用不同的用户,并为请求报价的人使用不同的用户,则$user
始终成为用户3。
尽管如此,正确的用户仍然会收到正确的消息。目前这仅影响谁在quoteReply
函数中获取正确的电子邮件。
导致这种情况的原因是什么?
答案 0 :(得分:1)
开关
$userID = $message->value('user_id');
到
$userID = $message->user_id;
解决了我的问题。