Live from the community
Live public code drops
Code feed
Code worth pausing your scroll for.
Filter your feed
Community signal
Shuffle
Dinesh Uprety
@dineshuprety ·
Constrain relationships once
Original CodeSnap example inspired by Laravel News. Source: https://laravel-news.com/eloquent-tips-tricks
PHP
Cyber
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
CREATED WITH CODESNAP
#mecha-core
319 views
Aug 23, 2026
You’re all caught up.