所以我有一个票务系统,我想做的是当用户发布评论时,另一方应收到一封电子邮件,这是我到目前为止完成的:
在注释controller中:
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: CareRepositoriesEloquentUsersRepository::$93
我知道它的变量分配有问题,但我找不到它,所以如果您能提供帮助,请很棒。
谢谢
我认为这是罪魁祸首。
//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);
}