Let's suppose I have the following related tables:
pages
----------------
id
content
visitors
----------------
id
name
page_visitor
----------------
page_id
visitor_id
As you see can we have three tables, in which pages
and visitors
have a many-to-many relationship.
I have successfully implemented an observer class on the pages
model class, and now, what ever I do to the pages table gets reflected somewhere else. Using the following code:
class ElasticsearchPageObserver
{
private $elasticsearch;
public function __construct(ESClient $client)
{
$this->elasticsearch = $client;
}
public function created(Page $page)
{
$params = $page->buildElasticsearchParams();
$response = $this->elasticsearch->index($params);
}
public function updated(Page $page)
{
$params = $page->buildElasticsearchParams();
$response = $this->elasticsearch->index($params);
}
}
You get the idea, right?
As it turns out, when the tables that have a one-to-many relationship with the page table get updated, the above observer, observes it. But not for many-to-many relationships(like the above).
Well, now how do I go about this??? How to do the same thing when page_visitor
gets updated?
Thanks