Did you know that in Laravel there was a method called getRelatedIds on the belongs to many relationship?

It was renamed to allRelatedIds and it can be used as an alternative to pluck('id') to get all of the IDs for the related models.

<?php
// instead of
$article->tags()->pluck('id')->toArray();

// you can use
$article->tags()->allRelatedIds()->toArray();