Posted: 24-11-2019

Laravel modelKeys

Laravel modelKeys

@AlexVanderbist on twitter shares this nice shorthand using the modelKeys method to returns the primary keys for all models in the collection. 

//instead of this
$product->attributes->pluck('id')->toArray();

//You can use
$product->attibutes->modelKeys();