Laravel Collection Public API: only
The only method allows you to retrieve specific key/value pairs from a collection based on the keys supplied in the $keys array. For example, you can use it to get only the first_name and last_name values from a collection of users. After executing the only method, you will receive a new collection containing the desired key/value pairs.