Question about images()->first()

<?php echo $casestudy->images()->first()->url() ?>

I use this code to take the first image of my content.
this works perfect.
But i thought when re-ordening my images in the panel, the first image would change and become the first in this list in the left.
Am I missing something? -as it doesn’t-


You have to sort images first by the sort field:

$firstimage = $casestudy->images()->sortBy('sort', 'asc')->first();

But as I said in the other thread, never call a call method without checking if you got an object first! Otherwise, if there is no image in the folder, you get an error.

if($firstimage) {
echo $image->url();

just like @texnixe said. you can find it in the docs here…