所以我有一个票务系统,我想做的是当用户发表评论时,另一方应该收到一封电子邮件,这是我迄今为止所取得的成就:
在CommentsController中:
public function postComment($id) {
$content = trim(Input::get('content'));
if (empty($content)) {
return Redirect::back();
}
if (Auth::user()->isAdmin() || $this->tickets->isTicketBelongsToUser(Auth::user()->id, $id)) {
if (Input::hasFile('attachment')) {
$attachmendId = Uploader::attach(Input::file('attachment'));
}
$comment = $this->comments->getNew(['content' => Input::get('content'), 'user_id' => Auth::user()->id, 'attachment_id' => isset($attachmendId) ? $attachmendId : null, 'ticket_id' => $id]);
//START geting the user id and send email//
$client = $this->users->$id;
$this->userMailer->CommentRespond($id);
//END geting the user id and send email//
$this->comments->save($comment);
}
return Redirect::back()->withMessage('Your comment has been sent');
}
在UserMailer.php中:
public function CommentRespond(User $user)
{
$view = 'emails.new-comment';
$subject = 'New Comment has been posted';
$data = [
'name' => $user->name
];
return $this->sendTo($user->email, $subject, $view, $data);
}
错误:
ErrorException (E_NOTICE)
Undefined property: Care\Repositories\Eloquent\UsersRepository::$93
我知道变量分配有问题,但我无法找到它,所以如果你能提供帮助那就太好了。
感谢
答案 0 :(得分:1)
我认为这是罪魁祸首。
//START geting the user id and send email//
//$client = $this->users->$id; <-- Wrong One
$client = $this->users->id;
$this->userMailer->CommentRespond($id);
我建议你转换成这个。
更新: 将用户行的检索更改为
$client = $this->users->getById($id);
$this->userMailer->CommentRespond($client);
然后更新CommentRespond
public function CommentRespond($user)
{
$view = 'emails.new-comment';
$subject = 'New Comment has been posted';
$data = [
'name' => $user['name']
];
return $this->sendTo($user['email'], $subject, $view, $data);
}