laravel latest from relationship 1

laravel latest from relationship

/**
 * Get the user's most recent image.
 */
public function latestImage()
{
    return $this->morphOne(Image::class)->latestOfMany();
}

Here is what the above code is Doing:
1. We’re using the morphOne() method to define a relationship between the User model and the Image model.
2. We’re using the latestOfMany() method to get the user’s most recent image.

Now, let’s create the latestOfMany() method in the Image model:

Similar Posts