venveo / craft-collections
Use Laravel Collections in Craft CMS Plugins
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 7
Forks: 1
Open Issues: 0
Type:craft-plugin
Requires
- illuminate/support: ^5.2
This package is auto-updated.
Last update: 2022-02-01 13:02:21 UTC
README
Collections is a really powerful Laravel class that provides "a fluent, convenient wrapper for working with arrays of data". Don't just take our words for it, Adam Watham is working on a book called "Refactoring to Collections" and he also has a great screencast on using collections..
There are often times when we are working with Craft CMS and wish we had Collections support, so we decided to build this plugin!
Requirements
Installation and Setup
- Download plugin release from this page
- Rename the download directory to
collections
and move into yourplugins
directory - Install Collections from the control panel settings
Example Usage
When working with data that is in an array...
$array = [
'eight', 'six', 'seven', 'five'
];
You can easily make the array a Collection using the following code:
$collection = craft()->collections->make($array);
Once you have your data in a Collection, you can instantly reap the rewards!
For example you can get the count of items in the array/Collection by simply calling:
$collection->count();
Wham-o! the count, in this case 4
, will be easily available!
What if you need to ensure that an array contains and item?
if ($collection->contains('six')) {
// returns true, then do something about it!
}
For the complete list of options when using Collections, see the list of available methods.
Credits
About Venveo
Venveo is a Digital Marketing Agency for Building Materials Companies in Blacksburg, VA. Learn more about us on our website.
License
The MIT License (MIT). Please see License File for more information.