Skip to content

Instantly share code, notes, and snippets.

Avatar

George Thuo gthuo

  • Kensoft Business Systems
View GitHub Profile
@gthuo
gthuo / autoPlural.php
Last active Jan 2, 2019
Automatically Pluralize Nouns in Laravel
View autoPlural.php
<?php
// 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)