We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
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();
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.