Trigger Laravel Scout update from outside Laravel

513 views Asked by At

I have a Laravel backend which basically works as an API and dashboard for my database and its data. The data updated daily using a Python script directly to the database. Is there any way to trigger a Laravel Scout update (so that the row is updated in Algolia as well) outside the PHP project?

The only alternative I thought was to use a Laravel api to handle the changes between the python script and the database so that only Laravel can communicate directly to the database.

However, I would really prefer if there was a way to add a listener or whatever to that without using Laravel in between since the python script is REALLY fast.

2

There are 2 answers

2
Giorgi Khurtsidze On BEST ANSWER

There are two ways for that:

1). You can use Laravel API to update Algolia entries into database.

2). Maybe you can use Algolia Python Library.

I suggest you to use Laravel API. You can simply call API URL from Python Script. You need to write clear PHP code of Laravel controller API, because python is fast and it will need to communicate fast with api.


Also: You can simply use Python module named flask to connect to your laravel database and make changes what you want in database. (Every database can be managed from different programming languages such as PHP, Ruby on Rails, Python and etc.)

Only laravel can't communicate to your database, it can be done from Python too (But of course it's mainly possible from laravel too).

0
Julien Bourdeau On

If you want to reindex everything, which seems to be the best way for you, I would just execute php path/to/artisan scout:import "App\Model" via Python.

If you want to update each model, because you will only edit a very limited number, like Giorgi said, I would use the Algolia Python client and call Algolia's API directly. It should be very easy to write. https://github.com/algolia/algoliasearch-client-python