Merge Laravel collections keys in only string
You can use PHP implode()
or Laravel ->implode()
method on collection:
implode(',', $collection->toArray());
$collection->implode(',');
use implode https://laravel.com/docs/5.3/collections#method-implode
if $collection is the value you have shown then
dd($collection->implode(','));
should give the expected result
And if it's a multi-dimensional array, implode
can also accept first arg as the key name:
$collection = collect([
[ 'title' => 'Hello world' ],
[ 'title' => 'Another Hello world' ]
]);
$collection->implode('title', ',')