2017-06-06 48 views
0

所以我有一票制,以及我想要做的是,當用戶發表評論對方應該收到一封電子郵件,這裏是我到目前爲止已經完成:Laravel 4.2發送電子郵件給用戶後響應後

在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 

我知道它有什麼毛病可變分配,但我無法找到它了,所以請如果你能幫助將是巨大的。

謝謝

回答

1

我認爲這是罪魁禍首。

//START geting the user id and send email//  
//$client = $this->users->$id; <-- Wrong One 
$client = $this->users->id; 
$this->userMailer->CommentRespond($id); 

我建議你轉換爲此。

UPDATE: 用戶行的檢索改爲

$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); 
} 
+0

感謝您的重播,但仍然得到錯誤「未定義的屬性:護理\庫\雄辯\ UsersRepository: :$ id爲「 –

+1

:) – Kzy

+0

遠高於更新,還是男人我得到一個錯誤‘未定義的屬性:護理\庫\雄辯\ UsersRepository :: $ id爲’ –

相關問題