Skip to content

Stop Selecting Every Column

Quick Tips•
November 2, 2026

Article::all() and ->get() run SELECT *. On a wide table that drags every LONGTEXT body, JSON metadata column, and cached HTML blob into PHP memory, even when the response only needs an id and a title. The bigger the rows, the more time you spend hydrating data you throw away.

Don't do this:

PHP
<?php declare(strict_types=1); namespace App\Http\Controllers; use App\Models\Article; use Illuminate\Http\JsonResponse; final readonly class ArticleListController { public function __invoke(): JsonResponse { // Pulls body, metadata, rendered_html, and every other column $articles = Article::query() ->latest('published_at') ->get(); return new JsonResponse($articles->map(fn (Article $article): array => [ 'id' => $article->id, 'title' => $article->title, ])); } }

Do this instead:

PHP
<?php declare(strict_types=1); namespace App\Http\Controllers; use App\Models\Article; use Illuminate\Http\JsonResponse; final readonly class ArticleListController { public function __invoke(): JsonResponse { $articles = Article::query() ->select(['id', 'title']) ->latest('published_at') ->get(); return new JsonResponse($articles->map(fn (Article $article): array => [ 'id' => $article->id, 'title' => $article->title, ])); } }

The second query reads two small columns instead of the whole row, so less data crosses the wire and less memory is allocated. List endpoints and dropdown queries are where this hurts most, because you fetch many rows and use a fraction of each. The select() list has to cover everything the code reads afterwards. An attribute you did not select comes back as null, unless Model::preventAccessingMissingAttributes() is on, which throws instead.