Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jonassiewertsen's avatar

whereBetween does not exist

Does anybody has a clue, why i'm getting this error?

It is working perfectly, exactly as i want it to on my dev server. Still, PHP Unit is squawking and giving me an error. It just doesn't makes sense ...

BadMethodCallException: Method Illuminate\Database\Eloquent\Collection::whereBetween does not exist.

My Controller looks like:


$bookings = auth()->user()->bookings()->get();

$thisWeek = $bookings->whereBetween('date', [
   now()->format('Y-m-d'), now()->endOfWeek()->format('Y-m-d')
  ]);

My PHPUnit Test:

\\ $this->withoutExceptionhandling();

$booking = create('App\Booking', [
    'user_id' => $this->user->id,
     'date' => now()->format('Y-m-d'),
 ]);

 $this->get(route('dashboard'))
   ->assertOK()
    ->assertSee($booking->date);

Does anybody has a clue?

0 likes
5 replies
tykus's avatar

The collection whereBetween method was added with Laravel 5.7.19, make sure you are running this version locally; run composer update to bypass the lock file.

It is working perfectly, exactly as i want it to on my dev server.

Probably your server is running the latest version of Laravel.

jonassiewertsen's avatar

Hmmm ... its weird.

I checked and both versions are the same


Laravel Framework 5.7.24
tykus's avatar

Hmmm.... it should be there. Check the Illuminate\Support\Collection class for the method, and if it's not there, then delete the vendor directory, and reinstall dependencies using composer install

realrandyallen's avatar

From @tykus earlier today:

Try running composer update rather than composer install so you are not using the lock file.

:^)

jonassiewertsen's avatar

@TYKUS - I just commented the test out. Opening the page up in my browser works perfectly, running it on the same machine via phpunit throws the error.

The method is listed in Collection class. Just weird.

Composer update doesn't change anything. I can't figure it out ...

Please or to participate in this conversation.