Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you skip Laravel Scout if enviroment is not production?

I have an app that I am writing with Laravel. I am still fairly new with the framework and don't understand most of it. I am using Algolia as the search engine with Laravel's Scout. In the models you add use Searchable, a trait, and the records are automatically passed to Algolia, which is cool. I am trying to put a simple statement if (App::environment('local'))" exit scout, just so we are not sending our development data to Algolia. Scout will also throw an exception if I run out of the hacker level of 10,000 records a Algolia.

like image 347
Chris Edwards Avatar asked Oct 16 '25 15:10

Chris Edwards


2 Answers

In your local .env add

SCOUT_DRIVER=null

In production add

SCOUT_DRIVER=algolia

In config/scout.php add

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

Automatically it will be ignored in local but work in production. This is just a suggestion. Try to adapt it to your specific context.

like image 131
EddyTheDove Avatar answered Oct 18 '25 07:10

EddyTheDove


On your local environment you can call YourModel::disableSearchSyncing(), which will prevent this model from pushing data to Algolia.

The reverse to this method is YourModel::enableSeachSyncing(), but the search is enabled by default, so usually there is no need to use it.

like image 32
Jan Petr Avatar answered Oct 18 '25 09:10

Jan Petr