Last active
January 13, 2022 03:44
-
-
Save jeffhappens/1a892c350c2ccda2e822 to your computer and use it in GitHub Desktop.
Laravel Helper function that converts a string to a possessive
This file contains 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 | |
// Add this function to app/helpers.php | |
if ( ! function_exists('str_possessive')) { | |
/** | |
* Make a string possessive. | |
* @param string $string | |
* @return string | |
*/ | |
function str_possessive($string) { | |
return $string.'\''.($string[strlen($string) - 1] != 's' ? 's' : ''); | |
} | |
} | |
?> | |
In composer.json add this block to "autoload" | |
"files": [ | |
"app/helpers.php" | |
] | |
// Run composer dump-autoload | |
// Usage: | |
<?php echo str_possessive('Your String'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment