max li
max li

Reputation: 2457

Laravel how to Query Rows by Column in Eloquent

In Laravel, I can get the rows from a selected column in MySQL by a Laravel query.

$data = DB::query('select engagements from csv2');

However, I wonder how can I write this using Eloquent?

Upvotes: 1

Views: 4174

Answers (2)

Mark Walker
Mark Walker

Reputation: 1279

Egill's answer works, however I find the below more readable.

$email = User::select('email')->get();

And for your follow up question.

Can i query rows that only has value on it

 $email = User::select('email')
    ->where('email', '!=', '')
    ->get();

Upvotes: 1

Egill
Egill

Reputation: 71

$data = Model::get(array('engagements'));

For example if I only want to get the E-mail for a user;

$email = User::get(array('email'));

Upvotes: 3

Related Questions