Fresh code drop

Get the latest related model

PHP

Original CodeSnap example inspired by Laravel News. Source: https://laravel-news.com/eloquent-tips-tricks

PHP
CodeSnap // free canvas

Get the latest related model

<?php

public function latestPost(): HasOne
{
    return $this->hasOne(Post::class)
        ->latestOfMany();
}

// Further reading: https://laravel-news.com/eloquent-tips-tricks

Turn your code into a post.Five templates are free—no account needed.

Remix this snap