简体   繁体   中英

get only selected column from database table laravel 5 eloqouent

I'm trying to get only the selected column in my database using Laravel 5 Eloquent, here's what i tried

$selected_vote = users_details::all()->get('selected_vote');

but unfortunately and sadly, not working. Any ideas, help, clues, suggestions?

Don't call all . Pass an array of columns to the get method:

$selected_votes = users_details::get(['selected_vote']);

If you just want a simple list for that column, you can use the lists method:

$selected_votes = users_details::lists('selected_vote');

If you only want a single value from the first row, use this:

$selected_vote = users_details::value('selected_vote');

You should pass an array of values to the get() method, like so:

users_details::get(['selected_vote']);

or you can use lists() method:

users_details::lists('selected_vote');

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