Black Friday: the Laravel testing course is $149 instead of $249, through Dec 7. See the course →
logo

A potential issue with full-text searches and Laravel feature tests

And how to solve it

Joel Clermont
Joel Clermont
2025-11-04

From our daily Laravel tips email. Get the next one in your inbox.

The RefreshDatabase trait is super useful for maintaining a clean database for each feature test. Recently, I ran into an issue with full-text indexes that prevented me from using that trait though.

I would create my data in the test, then exercise my endpoint which used Laravel's whereFullText method, but the search would return no results. This is because the full-text index is not updated until the transaction is committed.

So that won't play nice with the RefreshDatabase trait, which wraps each test in a transaction that stays uncommitted throughout the test execution and then is rolled back at the end of the test.

The solution in this case is to use the DatabaseMigrations trait instead of RefreshDatabase for these tests that require full-text index searching.

This trait is a little bit slower since it runs the migrations before each test and rolls them back afterward, but it ensures that the full-text index is properly updated and your searches will work as expected.

Here to help,

Joel

P.S. Next time you bump into a weird issue and you aren't sure how to solve it, remember I'm here to help.

Want a tip like this in your inbox every weekday?

Each one takes less than 2 minutes to read. Join 4,000+ Laravel developers who already get them.

email
No spam. Only real-world advice.
Toss a coin in the jar if you found this helpful.