2017-06-06 18 views
0

私はチケットシステムを持っています。私がしたいことは、ユーザーが電子メールを受け取るべきコメントを投稿するときです。 CommentsControllerでLaravel 4.2投稿応答後にユーザーに電子メールを送信

:UserMailer.phpで

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'); 
} 

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:CommentRespondを更新し

$client = $this->users->getById($id); 
$this->userMailer->CommentRespond($client); 

にユーザー列の検索を変更

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

"未定義のプロパティ:Care \ Repositories \ Eloquent \ UsersRepository :: $ id " –

関連する問題