Reputation: 43
For example, I want to select id, title from books instead of *, is there a way to do that?
Upvotes: 0
Views: 37
Reputation: 5024
Here is example:
$books = App\Book::select('id', 'title')->with('author')->get();
Upvotes: 0
Reputation: 4153
If you are using a relation, try this:
$book->author()->get(['id', 'title']);
The above query give you the id
and title
of the author
.
For simple queries, you can omit the relation:
$book->get(['id', 'title']);
This will return an array containing the id
and title
of the selected book.
Upvotes: 2