Last active
September 23, 2016 08:41
-
-
Save yashbarot/a82497a2d2cbd868b1113c9c02887c99 to your computer and use it in GitHub Desktop.
List of Laravel Helper functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Map function | |
| * | |
| * @return array | |
| */ | |
| function map($items, $func) | |
| { | |
| $result = []; | |
| foreach ($items as $item) { | |
| $result[] = $func($item); | |
| } | |
| return $result; | |
| } | |
| /** | |
| * Basic sumOf function | |
| * | |
| * @param string column_name | |
| * @param array $items | |
| * @return double | |
| */ | |
| function sumOf($column_name, $items) | |
| { | |
| $result = 0; | |
| foreach ($items as $item) { | |
| $result += $item->$column_name; | |
| } | |
| return $result; | |
| } | |
| /** | |
| * Get listOf values for specific key using collection | |
| * | |
| * @param string column_name | |
| * @param array $items | |
| * @return array | |
| */ | |
| function listsOf($column_name, $items) | |
| { | |
| $lists = []; | |
| $collection = collect($items); | |
| $lists = $collection->lists($column_name)->all(); | |
| return $lists; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment