Laravel Scout: Isolating Testing environment

Tracing source code from Laravel and Laravel Scout

Yish
Yish
Aug 25, 2017 · 2 min read

When I configure the website, I decided using Laravel Scount to do full-text search engine, but here is a problem to me.

Problem:

Develop/Testing/Production environment can NOT be isolation

When I develop my project, the data will be upload to algolia, mixed production and develop data. Laravel scout supported null drvier, this config value must be using to isolate environment.

But when I set value to null, it cause a error.

Type error: Too few arguments to function Illuminate\Support\Manager::createDriver(),

Very interesting, when create driver cause a error, trace source code:

It will be call createNullDriver and trace Laravel scout source code:

So far so good, Looking NullEngine :

Stop, we are sure it’s NOT cause error by Laravel Scout, so what’s the problem to cause error? Seeing upon first error message:

Type error: Too few arguments to function Illuminate\Support\Manager::createDriver(),

And check .env value:

SCOUT_DRIVER=null

Get it, when .env value be called, it should be *real* null, and then cause error.

Solutions

We have two solutions by issues.

Changing environment pass value

Passing value set type to string by .env

SCOUT_DRIVER='"null"'

Changing default value

Setting testing environment value to default.

'driver' => env('SCOUT_DRIVER', 'null'),

And then set .env value on production:

SCOUT_DRIVER=algolia

It should be work.

Yish

Thinking

)

Yish

Written by

Yish

Never stop progressing. https://yish.dev

Yish

Yish

Thinking

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade