-
app/Models/Post.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; final class Post extends Model { public function scopePublished(Builder $query): Builder { return $query->where('published_at', '<=', now()); } }
-
app/Http/Controllers/BlogController.php
Open in GitHubuse App\Models\Post; final class BlogController { public function __invoke() { $posts = Post::published()->orderByDesc('published_at')->get(); return view('blog', compact('posts')); } }