Closed aasutossh closed 2 years ago
I am using algolia as search service. I want to sort by the views too. For that, I need to re index the table when view gets updated. And to achieve that I need to update the timestamp if the view has been recorded.
// record product view
$expiresAt = now()->addHours(3);
views($product)
->cooldown($expiresAt)
->record();
The record()
method returns boolean.
$expiresAt = now()->addHours(3);
if (views($product)
->cooldown($expiresAt)
->record()) {
$product->touch();
}
Seems to work fine.
I think the way you implemented it is fine. Another option would be to create an observer for the View model and watch for the created
event.
How do I go about implementing it? Is there some event that gets fired if the view has been recorded? Or I need to have my custom
Views.php
andView.php
?