Skip to content

Commit fec7176

Browse files
committed
removed get() and latest() references in model scopes
1 parent 200bc86 commit fec7176

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/Cmgmyr/Messenger/Models/Thread.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function participants()
6767
*/
6868
public static function getAllLatest()
6969
{
70-
return self::latest('updated_at')->get();
70+
return self::latest('updated_at');
7171
}
7272

7373
/**
@@ -99,9 +99,7 @@ public function scopeForUser($query, $userId)
9999
return $query->join('participants', 'threads.id', '=', 'participants.thread_id')
100100
->where('participants.user_id', $userId)
101101
->where('participants.deleted_at', null)
102-
->select('threads.*')
103-
->latest('updated_at')
104-
->get();
102+
->select('threads.*');
105103
}
106104

107105
/**
@@ -120,9 +118,7 @@ public function scopeForUserWithNewMessages($query, $userId)
120118
$query->where('threads.updated_at', '>', $this->getConnection()->raw($this->getConnection()->getTablePrefix() . 'participants.last_read'))
121119
->orWhereNull('participants.last_read');
122120
})
123-
->select('threads.*')
124-
->latest('updated_at')
125-
->get();
121+
->select('threads.*');
126122
}
127123

128124
/**

src/Cmgmyr/Messenger/examples/MessagesController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public function index()
3333
$currentUserId = Auth::user()->id;
3434

3535
// All threads, ignore deleted/archived participants
36-
$threads = Thread::getAllLatest();
36+
$threads = Thread::getAllLatest()->get();
3737

3838
// All threads that user is participating in
39-
// $threads = Thread::forUser($currentUserId);
39+
// $threads = Thread::forUser($currentUserId)->latest('updated_at')->get();
4040

4141
// All threads that user is participating in, with new messages
42-
// $threads = Thread::forUserWithNewMessages($currentUserId);
42+
// $threads = Thread::forUserWithNewMessages($currentUserId)->latest('updated_at')->get();
4343

4444
return View::make('messenger.index', compact('threads', 'currentUserId'));
4545
}

tests/EloquentThreadTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function it_should_return_all_threads()
6363
$this->faktory->create('thread', ['id' => ($index + 1)]);
6464
}
6565

66-
$threads = Thread::getAllLatest();
66+
$threads = Thread::getAllLatest()->get();
6767

6868
$this->assertCount($threadCount, $threads);
6969
}
@@ -100,7 +100,7 @@ public function it_should_get_all_threads_for_a_user()
100100
$participant_2 = $this->faktory->create('participant', ['user_id' => $userId, 'thread_id' => $thread2->id]);
101101
$thread2->participants()->saveMany([$participant_2]);
102102

103-
$threads = Thread::forUser($userId);
103+
$threads = Thread::forUser($userId)->get();
104104
$this->assertCount(2, $threads);
105105
}
106106

@@ -117,7 +117,7 @@ public function it_should_get_all_threads_for_a_user_with_new_messages()
117117
$participant_2 = $this->faktory->create('participant', ['user_id' => $userId, 'thread_id' => $thread2->id, 'last_read' => Carbon::yesterday()]);
118118
$thread2->participants()->saveMany([$participant_2]);
119119

120-
$threads = Thread::forUserWithNewMessages($userId);
120+
$threads = Thread::forUserWithNewMessages($userId)->get();
121121
$this->assertCount(1, $threads);
122122
}
123123

0 commit comments

Comments
 (0)