How to make first image of child as thumb in parent pages list?

Maybe this was already asked, but can’t find solution.

I have list of Projects
Child Project has section with files.

Now in Projects pages list thumb of child is probably the first uploaded file, but I want to make it the one, that is first in sort of files.

I think you want sort on the files sort order… something like this…

$page->files()->sortBy('num', 'asc')->first()

Which will give you just the first image, if you take ->first() off the end, you will get all the images, sorted by sort order.

You mean for frontend? That’s already done, but I mean in panel.


image: page.images.first

in the pages section

Thank you, I see it’s affecting order, for example image: page.images.last gives another thumb, but in my case with image: page.images.first there is still another thumb, than is first by my manual order :man_shrugging:

Looks like it’s considering file names, but not order.

Ok, I understand now the logic :slight_smile: cool, it’s working with image: page.cover

and model:


class ProjectsPage extends Page {
    public function cover() {
        return $this->content()->get('cover')->toFile() ?? $this->images()->sortBy('sort', 'asc')->first();