One of the lesser-known but highly useful functions in Laravel is modelKeys.

The modelKeys method returns the primary keys for all models in the collection?

So, instead of doing this:

<?php
$key = Post::all()->pluck('id');

You better do this:

<?php
$keys = Post::all()->modelKeys();

The $keys variable will contain an array with the primary key column values. The key types are typically 'int' for integer primary keys and 'string' for string-based primary keys, but they can vary depending on your migration setup.