RoboRobok
1 month ago
124
7
Laravel

Is there such method in Collection?

Posted 1 month ago by RoboRobok

I need to replace each array entry to ['column' => $value]. Is there such method in Laravel's Collection?

For now I do it as:

$animals = collect(['dog', 'cat', 'tiger']);

$columnized = $animals->map(function (string $animal): array {
    return ['animal' => $animal];
});

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