How to get specific columns using Laravel eloquent methods

You can get specific columns using Laravel eloquent methods (all(), first(), find()) while getting the data from tables. You have to specify the columns name in array to the eloquent methods.

Answers 2
  • Get specific column using Laravel all() eloquent method

    App\Models\User::all(['id', 'name', 'email']);
    
    0

    You can get all users' records from the users table with column id, name and email.

  • Get specific columns using get() eloquent method in Laravel

    App\Models\User::where('name', 'summer')->get(['id', 'name', 'email']);
    
    0

    You can get all users' records from the users table using where condition with values of specified columns (id, name and email).

  • Back to code snippet queries related laravel