Reputation: 20329
I have been succesful in uploading my data to algolia using laravel. My create method looks like this:
Beer::firstOrCreate([
'name' => $beer['title'],
'description' => $beer['description'],
'path' => '/uploads/gall/' . $filename,
'brewery_id' => '',
'abv' => $abv
]);
It gathers data from an api and works perfectly, except for the abv value. It needs to be a numeric type in algolia but whenever I check it in algolia it is a string.
Even when I force it to a float or int by using:
(float)$abv
I still end up with a string in my Algolia database. Funny enough the primary id for this record that is being auto incremented is not a string and looks fine in the algolia database.
To implement algolia in laravel I used the laravel helper in my model:
// Send new records to the algolia database
use AlgoliaEloquentTrait;
I hope somebody can maybe give me slight hint of what I could be doing wrong.
Upvotes: 1
Views: 106
Reputation: 2366
I am assuming that the data type of 'abv' inside your database is float and not string, if this is the case then try using floatval($abv)
. Your code would be something like:
Beer::firstOrCreate([
'name' => $beer['title'],
'description' => $beer['description'],
'path' => '/uploads/gall/' . $filename,
'brewery_id' => '',
'abv' => floatval($abv)
]);
Cheers,,
Upvotes: 1