Last active
October 12, 2018 20:44
-
-
Save kennyray/99e6614e85c50c9dc55cdd89002b82f5 to your computer and use it in GitHub Desktop.
Laravel Eloquent only()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$fullModel = Model::find(1) // Get model with id 1 | |
$idArray = $fullModel->only('id') // array containing id | |
// this does not work. You'll get back an empty collection | |
// It is trying to pull the id column off the collection object, | |
// not the models it contains | |
$models = Model::all() | |
$ids = $models->only('id') | |
// this will give you a collection of ids | |
$models = Model::all() | |
$ids = $models->pluck('id') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment