Ad

How Can I Get The Url Of Featured Image From Rainlab Blog Plugin?

I need to know the url of a featured image attached in a blog post with Rainlab blog plugin in October CMS.

The image is saved in a directory something like ".../storage/app/uploads/public/59f/112"

I need to know it in the moment that I save the post because I want to get the url to save it in another table that it can access from another php file or system ( in Android App for example ), but I can't do it.

I try with (in FormController.php) find the post:

$modelP = Post::find($this->controller->vars['formModel']['id']);
$featuredImage = $modelP->featured_image->getPath();

But doesn't work, I get the blog object but it says that featured_image is not a variable.

In the table system_file only I can get the name of the file (disk_name) but not the entire url and I don't know in what directory it is saved.

Can anyone help me?

Ad

Answer

If you are using rain lab plugin then we do have some solution

first its featured_images not featured_image

It will going to return you a collection of images so if you need first image of it, then you replace code like

$modelP = Post::find($this->controller->vars['formModel']['id']);
$featuredImage = $modelP->featured_images->first()->getPath();

$featuredImage this is full path of image

any other confusion please comment, happy coding :)

Ad
source: stackoverflow.com
Ad