By doing so you will have only the column that you need reducing the amount of data that you have to retrieve and possibly preventing any unnecessary data.
Laravel Model Get Specify Column Example
<?php $posts = Post::all(['id', 'title', 'slug']);
When you specify the code like above you will only get the "id", "title", and "slug" from all of the model instances that is being retrieved.
Do note that the code above can be optimized using "cursor()" and "chunk()" for better optimzation.
Leave a reply