Skip to content

Commit 5e2a291

Browse files
committed
added creator() method to Thread model
1 parent 9d11134 commit 5e2a291

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Cmgmyr/Messenger/Models/Thread.php

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ public function participants()
6060
return $this->hasMany('Cmgmyr\Messenger\Models\Participant');
6161
}
6262

63+
/**
64+
* Returns the user object that created the thread
65+
*
66+
* @return mixed
67+
*/
68+
public function creator()
69+
{
70+
return $this->messages()->latest()->first()->user;
71+
}
72+
6373
/**
6474
* Returns all of the latest threads by updated_at date
6575
*

src/Cmgmyr/Messenger/examples/views/index.blade.php

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<div class="media alert {{$class}}">
1313
<h4 class="media-heading">{{link_to('messages/' . $thread->id, $thread->subject)}}</h4>
1414
<p>{{$thread->latestMessage->body}}</p>
15+
<p><small><strong>Creator:</strong> {{ $thread->creator()->name }}</small></p>
1516
<p><small><strong>Participants:</strong> {{ $thread->participantsString(Auth::id()) }}</small></p>
1617
</div>
1718
@endforeach

0 commit comments

Comments
 (0)