简体   繁体   中英

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?

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

例如,如果我只想为用户收到电子邮件;

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM