Roman
February 2, 2021, 10:30pm
1
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.
Roman
February 2, 2021, 10:36pm
3
You mean for frontend? That’s already done, but I mean in panel.
Roman
February 2, 2021, 11:11pm
5
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
Looks like it’s considering file names, but not order.
Roman
February 2, 2021, 11:16pm
6
Ok, I understand now the logic cool, it’s working with image: page.cover
and model:
<?php
class ProjectsPage extends Page {
public function cover() {
return $this->content()->get('cover')->toFile() ?? $this->images()->sortBy('sort', 'asc')->first();
}
}