Skip to content

Instantly share code, notes, and snippets.

View gthuo's full-sized avatar

George Thuo gthuo

View GitHub Profile
gthuo / autoPlural.php
Last active January 2, 2019 19:52
Automatically Pluralize Nouns in Laravel
// this function will return the plural or singular depending on the integer passed
//eg if $count=1 and $noun="post", it will echo 1 post..if $count!=1, it will echo X posts
*@param count - Can be an integer, or a collection (which we use count() to know size) to know whether it is plural or singular
*@param noun - the noun to pluralize or sigularize
*@param return - to determine either to return it (eg when used in a controller) or echo it (default - eg used in a blade template)
*@param return_noun_only - when you only need the noun, and not the numeric part of it
function autoPlural($count,$noun=null,$return = false,$return_noun_only=false)