The Blog

Laravel

Laravel String Helper Function: camel

John Koster
John Koster
November 16, 2016

Learn how to use the camel helper function in Laravel's Illuminate\Support\Str class to convert strings to camel case. Discover examples of how to convert various forms of strings to camel case, and understand that the function only affects the casings of the first character. Additionally, find out about the convenient camel_case function, which is a shortcut to calling Str::camel.

Laravel

Laravel String Helper Function: contains

John Koster
John Koster
November 16, 2016

Learn how to use the contains helper method in PHP to check if a given value contains any of the specified needles. The contains method returns true if any needles are found in the haystack, otherwise it returns false. Find out how you can easily call this method using the str_contains function, a shortcut to Str::contains.

Laravel

Laravel String Helper Function: ends_with

John Koster
John Koster
November 16, 2016

The endsWith helper method in Laravel is used to check if a string ends with any of the provided characters. It returns true if the string ends with any of the characters and false otherwise. This method can be used in combination with PHP's range function to check if a string ends with any alphabetical character. Additionally, there is a shortcut function ends_with that can be used instead of calling Str::endsWith directly.

Laravel

Laravel String Helper Function: equals

John Koster
John Koster
November 16, 2016

The equals method in Laravel compares two strings to check if they are the same. It returns a boolean value indicating whether the strings are equal or not. This method implements a constant-time algorithm, so the time it takes to complete doesn't increase with the size of the strings. However, starting from Laravel version 5.2, it is recommended to use PHP's built-in hash_equals function instead. The equals method may leak length information through timing attacks if the input strings have different lengths. For more information on security considerations and relevant resources, please refer to the provided links.

Laravel

Laravel String Helper Function: finish

John Koster
John Koster
November 16, 2016

The finish helper method is a useful tool for ensuring that a given value ends with a specified character or string. It's commonly used for constructing URIs or file paths, and can accept any string of characters as the ending. This helper function is particularly handy when combined with the slug method, allowing for easy generation of interesting results. Additionally, for convenience, there is a shortcut function called str_finish that can be used in the global namespace.

Laravel

Laravel String Helper Function: is

John Koster
John Koster
November 16, 2016

The is helper method is used to determine if a value matches a specific pattern. It returns true if the value matches the pattern, and false otherwise. You can use wildcards in the pattern for flexible matching. The str_is function is a shortcut for calling the is method. It can be used globally without the need for importing the Str class.

Laravel

Laravel String Helper Function: length

John Koster
John Koster
November 16, 2016

The length helper method in Laravel returns the length of a given value in PHP. It utilizes PHP's internal character encoding to calculate the length. For example, Str::length('12345') would return 5, and Str::length(str_repeat('n', 120)) would return 120. Additionally, str_repeat is a PHP function that repeats a given input a specified number of times, such as str_repeat('n', 120) resulting in a string with 120 occurrences of the character 'n'.

Laravel

Laravel String Helper Function: limit

John Koster
John Koster
November 16, 2016

The limit method is a useful helper function in Laravel's Str class that ensures a provided value does not exceed a specified limit. It appends a given end sequence if the value is trimmed. This is particularly useful when displaying lengthy user-generated content to avoid issues with UI layouts. The str_limit function is a shortcut to calling Str::limit and is defined in the global namespace.

Laravel

Laravel String Helper Function: lower

The lower helper method converts a given value to lowercase. Use the lower function by passing the desired value as an argument. For example, Str::lower('ALL LOWER CASED') will output "all lower cased".

Laravel

Laravel String Helper Function: parse_callback

John Koster
John Koster
November 16, 2016

Learn how to use the parseCallback helper method in Laravel to split a string with a class name and method name. With the $default parameter, you can specify a default method if no method name is provided. The parseCallback function returns an array containing the class name and method name. Check out some examples of usage to understand how it works.

Latest posts

That Escalated Quickly: All the New Things

The past six months or so have been incredibly busy. What started as a new article series about cust...

Read more
Troubleshooting a Statamic Illegal Offset Type Error when Viewing Collection Entries in the Control Panel

In this post I talk about how I resolved a mysterious illegal offset type error when viewing collect...

Read more
Creating Simple HTTP Redirect Routes from a Statamic Site

Generating a custom Laravel routes file from a Statamic website to redirect to a new domain.

Read more
Disabling Vite File Hashes

Disabling file hashes in Vite output can be accomplished by modifying your project's vite.config.js

Read more
Implementing a Custom Laravel Blade Precompiler for Volt and Livewire

Learn how to implement a custom component compiler for Laravel's Blade templating language in this p...

Read more
Creating a Hybrid Cache System for Statamic: Part Five

Part 5 of 6 covers implementing a cache namespace and labeling system, which we can use to target mu...

Read more