$collection = collect([ ['account_id' => 1, 'product' => 'Desk'], ['account_id' => 2, 'product' => 'Chair'], ]); $collection->implode('product', ', '); // Desk, Chair
Here is what the above code is Doing:
1. We create a collection of associative arrays.
2. We call the implode method on the collection.
3. We pass the key of the values we want to implode as the first argument.
4. We pass the glue as the second argument.
5. The method returns a string of the values imploded by the glue.