Skip to content

Commit e3ff7ad

Browse files
committed
add version checking for Laravel 5.1+ where the lists() functionality has changed
1 parent bdb793c commit e3ff7ad

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

phpunit.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@
1515
<directory suffix="Test.php">./tests/</directory>
1616
</testsuite>
1717
</testsuites>
18+
<php>
19+
<env name="APP_ENV" value="testing"/>
20+
<env name="CACHE_DRIVER" value="array"/>
21+
<env name="SESSION_DRIVER" value="array"/>
22+
<env name="QUEUE_DRIVER" value="sync"/>
23+
</php>
1824
</phpunit>

src/Cmgmyr/Messenger/Traits/Messagable.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ public function threadsWithNewMessages()
4545
$threadsWithNewMessages = [];
4646
$participants = Participant::where('user_id', $this->id)->lists('last_read', 'thread_id');
4747

48+
/**
49+
* @todo: see if we can fix this more in the future.
50+
* Illuminate\Foundation is not available through composer, only in laravel/framework which
51+
* I don't want to include as a dependency for this package...it's overkill. So let's
52+
* exclude this check in the testing environment.
53+
*/
54+
if (getenv('APP_ENV') != 'testing') {
55+
if (!str_contains(\Illuminate\Foundation\Application::VERSION, '5.0')) {
56+
$participants = $participants->all();
57+
}
58+
}
59+
4860
if ($participants) {
4961
$threads = Thread::whereIn('id', array_keys($participants))->get();
5062

0 commit comments

Comments
 (0)