Collect columns from Collection

Posted 2 years ago by oolongtea

What is the correct way to select column fields from a Model with related models. For example,

$all = Task::with('creator', 'approver', 'manager')->get();

I tried using get(), select and seems like there's no simple solution.

So I'm decided to loop through the collection and pick the columns I want.

Should I use For Each and then Collect? Could you suggest an efficient way?


Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.