Hi,
How can I remove specified columns from a collection after using Query Builder's get()?
For example, I have a query:
$collection = DB::table('table')->get();
And I get a collection of all the columns:
Illuminate\Support\Collection {
#items: array:100 [
0 => {
"id": "1"
"first_name": "John"
"last_name": "Doe"
}
1 => {
...
}
2 => {
...
}
...
]
}
I use the same query in several pages. In some pages I need all the columns, but in some I don't need all, like in the above collection in some pages I don't want the id column, only first_name and last_name.
The forget() method doesn't work, I think because it's nested and the forget() tries to go by the numeric keys
How can I do that? So that my end collection would be:
Illuminate\Support\Collection {
#items: array:100 [
0 => {
"first_name": "John"
"last_name": "Doe"
}
1 => {
...
}
2 => {
...
}
...
]
}
thanks