Download the PHP package ndp/customcollect without Composer
On this page you can find all versions of the php package ndp/customcollect. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package customcollect
Laravel Collection Select Statement
About
This package adds a select method statement to the Laravel collection class and allows you to use it similar to a SQL select attribute statement and returns a collection of dynamic objects. Note that laravel select statement before a fetch should still be used. This is approach better fits mutating instances that don't extend the laravel Model class.
Usage:
Lets say you have some classes like these.
A current of way of setting response objects.
The static method get() in this case will return a collection. In most cases, you would need to loop through each object, after manipulating which properties will be send or hidden to front-end, then you could create a dynamic object so this can be passed to the front end as json etc..
A much more convenient way of setting response objects in a collection.
To save some time in data presentation you can use the select statement with a property and its new property name separated by " as ". Also, you can traverse through embedded relation or properties within the given class using the dot operator.Note, in the select method string argument, you can go several properties deep for the objects it will be transversing as shown below.
Note that eager loading it's not necessary. The select method currently supports only getters to fetch its values.
You can also have a callback per looped object.
For properties that need more than just renaming, simply define a method callback at the end the arguments like so. The method callback will contain two parameters.
- The $dummy object is passed per reference so no need to specify a return statement.
- The $eventObject is passed by value and can be used to concat properties.
Package Installation
Install it in your project via composer require.
Optional: