From 2441a98bfbb5d8b66f197a1b6deb37536b4fb932 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Thu, 14 Sep 2017 01:15:13 -0300 Subject: [PATCH] Doc specification of columns in with method --- eloquent-relationships.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/eloquent-relationships.md b/eloquent-relationships.md index f997610a5e..9f0ef9fa6f 100644 --- a/eloquent-relationships.md +++ b/eloquent-relationships.md @@ -813,6 +813,16 @@ In this example, Eloquent will only eager load posts where the post's `title` co $query->orderBy('created_at', 'desc'); }])->get(); +You may use [select](/docs/{{version}}/queries#selects) method to specify a custom select clause for the query: + + $users = App\User::with(['posts' => function ($query) { + $query->select(['id', 'title']); + }])->get(); + +Or you may specify the columns to eager load directly in the `with` method: + + $users = App\User::with('posts:id,title')->get(); + ### Lazy Eager Loading