I've two databases.
wordpress: database1
mysql: database2
database1 has table wp_posts (Post.php model)
database2 has table news_tag(NewsTag.php model) and publishers(Publisher.php) model.
wp_posts has:
id
news_tag has:
id
post_id
publisher_id
publishers have:
id
I'm trying to access the publisher from the wp_posts. How can I achieve it?
In the Post.php model, I've tried something like:
public function publisher() {
return $this->hasManyThrough(
Publisher::Class,
NewsTag::Class,
'post_id',
'publisher_id',
'id',
'id',
'id');
}
Maybe I'm not being able to access multiple databases in same model? I'm getting this error:
SQLSTATE[42S02]:
Base table or view not found: 1146 Table 'db_news.wp_publishers' doesn't exist
(SQL: select `wp_publishers`.*, `wp_news_tags`.`post_id` as `laravel_through_key`
from `wp_publishers` inner join `wp_news_tags` on `wp_news_tags`.`id` =
`wp_publishers`.`publisher_id` where `wp_news_tags`.`post_id` in (?) and
`wp_publishers`.`deleted_at` is null and `wp_news_tags`.`deleted_at` is null)