Skip to content
Advertisement

Laravel – how to copy collection to a new variable

I wanted to change my collection set to a new variable, but it changed the original.

I thought this was a JavaScript issue and PHP was referring to value.

How do I set my collection to a new variable, which I can alter without changing the original collection.

JavaScript

I’m using this workaround for now:

JavaScript

Advertisement

Answer

Try using clone

JavaScript

If you like to use collection then add method to collection using macro in AppServiceProvider boot method

JavaScript

then you can do the following

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement