Fresh code drop

Constrain relationships once

PHP

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

PHP
CodeSnap // free canvas

Constrain relationships once

<?php

public function publishedPosts(): HasMany
{
    return $this->hasMany(Post::class)
        ->whereNotNull('published_at')
        ->latest('published_at');
}

// 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