Skip to content

Commit

Permalink
added creator() method to Thread model, closes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgmyr committed Jun 1, 2015
1 parent 6118046 commit 8e56c4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Cmgmyr/Messenger/Models/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public function participants()
return $this->hasMany('Cmgmyr\Messenger\Models\Participant');
}

/**
* Returns the user object that created the thread
*
* @return mixed
*/
public function creator()
{
return $this->messages()->latest()->first()->user;
}

/**
* Returns all of the latest threads by updated_at date
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<div class="media alert {!!$class!!}">
<h4 class="media-heading">{!! link_to('messages/' . $thread->id, $thread->subject) !!}</h4>
<p>{!! $thread->latestMessage->body !!}</p>
<p><small><strong>Creator:</strong> {!! $thread->creator()->name !!}</small></p>
<p><small><strong>Participants:</strong> {!! $thread->participantsString(Auth::id()) !!}</small></p>
</div>
@endforeach
Expand Down

0 comments on commit 8e56c4b

Please sign in to comment.