Pick up specific columns with Laravel querybuilder

Asked

Viewed 1,882 times

2

Consider that my table in DB has many columns. However, for a specific query I do not need all of them. As I would in Laravel ( using both Eloquent and Querybuilder to pick up only the columns I need?

1 answer

4


To set the columns you want to select use select:

DB::table('nome_da_tabela')->select('coluna1', 'coluna2')->get();

As found in the documentation.

  • Set descrica_da_column? "name, age, email" for example.

  • That’s ai! DB::table('users')->select('name','email')->get();

  • Any idea what I’d look like using Eloquent?

  • 1

    @Cesardebarros in the same way... User::select('name','email')->get();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.