Return all data in a model

Probably a silly question. I have set up a module called Pages. I have created a blog page. I have set up a module called Blogs. I know how to get the blogs on the blog page, how do I get the media too? Done a foreach loop, $post->image() etc, but no luck. Any ideas please?
2 Replies
pauldwight
pauldwight2mo ago
Hi @Steven ✈ assuming you have setup the mediaParams and HasMedias trait in your Post model you grab the media like this
// in Post model
public $mediasParams = [
'grid' => [
'default' => [
[
'name' => 'default',
'ratio' => 3 / 4,
],
],
],
];

// In View (role,crop)
$image = $post->image('grid','default');
$imageAltText = $post->imageAltText('grid','default');
// in Post model
public $mediasParams = [
'grid' => [
'default' => [
[
'name' => 'default',
'ratio' => 3 / 4,
],
],
],
];

// In View (role,crop)
$image = $post->image('grid','default');
$imageAltText = $post->imageAltText('grid','default');
Steven ✈
Steven ✈OP2mo ago
Thank you so much! I will take a look and see what happens 🤩

Did you find this page helpful?