0

I am brand new to developing a custom October CMS plugin and I'm working on a plugin to extend RainLab.Blog where I can't seem to reference the current single post from my plugin's component when visiting an article.

Assuming I'm reading a blog post at www.example.com/:slug, I want to query my plugin's custom table where one of it's columns is a foreign key to RainLab.Blog's post, called "post_id".

When inspecting the table in PHP My Admin, I can see that the ID in column post_id is indeed the corresponding post ID for the correct post, but I know of no way to fetch the correct row using this ID.

I'm currently hardcoding the post ID to get, just to have something for the front end, like so:

return Business::where('post_id', 4) -> first();

This ofcourse refers to the 4th post no matter which post I'm reading. I can't seem to figure out how I'd go about targeting the "current" post. Any feedback would be much appreciated.

1 Answers1

0

Got it! After some tinkering, I replaced:

return Business::where('post_id', 4) -> first();

With this correction:

if ($this -> page['post'])  {
    return Business::where('post_id', $this -> page['post'] -> getAttribute('id')) -> first();
}