Debug School

rakesh kumar
rakesh kumar

Posted on • Updated on

Laravel String

  1. preg_replace_array(replaces a given pattern in the string)
  2. Str::after(returns everything after the given value in a string)
  3. Str::afterLast
  4. Str::ascii(attempt to transliterate the string into an ASCII value:)
  5. Str::before(returns everything before the given value in a string)
  6. Str::beforeLast(returns everything before the last occurrence of the given value in a string)
  7. Str::between(the portion of a string between two values)
  8. Str::betweenFirst
  9. Str::camel(converts the given string to camelCase)
  10. Str::contains(determines if the given string contains the given value)
  11. Str::containsAll(determines if the given string contains all of the values in a given array:)
  12. Str::endsWith(if the given string ends with the given value:)
  13. Str::excerpt( given string that matches the first instance of a phrase within that string:)
  14. Str::finish(adds a single instance of the given value to a string)
  15. Str::headline(will convert strings delimited by casing, hyphens, or underscores into a space delimited string with each word's first lette)
  16. Str::inlineMarkdown(converts GitHub flavored Markdown into inline HTML using CommonMark)
  17. Str::is(if a given string matches a given pattern)
  18. Str::isAscii(if a given string is 7 bit ASCII:)
  19. Str::isJson(if the given string is valid JSON:)
  20. Str::isUuid(if the given string is a valid UUID:)
  21. Str::kebab(converts the given string to kebab-case:)
  22. Str::lcfirst(given string with the first character lowercased:)
  23. Str::length( returns the length of the given string:)
  24. Str::limit(runcates the given string to the specified length:)
  25. Str::lower (converts the given string to lowercase)
  26. Str::markdown(converts GitHub flavored Markdown into HTML using CommonMark:)
  27. Str::mask(portion of a string with a repeated character, and may be used to obfuscate segments of strings such as email addresses and phone numbers:)
  28. Str::orderedUuid(generates a "timestamp first" UUID )
  29. Str::padBoth(padding both sides of a string with another string until the final string reaches a desired length)
  30. Str::padLeft(padding the left side of a string with another string until the final string reaches a desired length)
  31. Str::padRight( padding the right side of a string with another string until the final string reaches a desired length:)
  32. Str::plural( converts a singular word string to its plural form)
  33. Str::pluralStudly(method converts a singular word string formatted in studly caps case to its plural form)
  34. Str::random(generates a random string of the specified length)
  35. Str::remove(removes the given value or array of values from the string:)
  36. Str::replace(method replaces a given string within the string)
  37. Str::replaceArray(method replaces a given value in the string sequentially using an array:)
  38. Str::replaceFirst(The Str::replaceFirst method replaces the first occurrence of a given value in a string:)
  39. Str::replaceLast(The Str::replaceLast method replaces the last occurrence of a given value in a string:)
  40. Str::reverse(The Str::reverse method reverses the given string)
  41. Str::singular(The Str::singular method converts a string to its singular form)
  42. Str::slug(The Str::slug method generates a URL friendly "slug" from the given string:)
  43. Str::snake(The Str::snake method converts the given string to snake_case:)
  44. Str::squish(removes all extraneous white space from a string, including extraneous white space between words:)
  45. Str::start(adds a single instance of the given value to a string if it does not already start with that value:)
  46. Str::startsWith(if the given string begins with the given value:)
  47. Str::studly(converts the given string to StudlyCase)
  48. Str::substr(portion of string specified by the start and length parameters:)
  49. Str::substrCount(returns the number of occurrences of a given value in the given string:)
  50. Str::substrReplace(method replaces text within a portion of a string,)
  51. Str::swap(replaces multiple values in the given string using PHP's strtr function:)
  52. Str::title(onverts the given string to Title Case)
  53. Str::toHtmlString(converts the string instance to an instance of Illuminate\Support\HtmlString)
  54. Str::ucfirst(returns the given string with the first character capitalized:)
  55. Str::ucsplit(splits the given string into an array by uppercase characters:)
  56. Str::upper(converts the given string to uppercase:)
  57. Str::ulid(generates a ULID)
  58. Str::uuid (generates a UUID (version 4):)
  59. Str::wordCount(returns the number of words that a string)
  60. Str::words (limits the number of words in a string)
  61. str(returns a new Illuminate\Support\Stringable instance of the given string)
  62. trans(translates the given translation key using your localization files:)
  63. trans_choice( translates the given translation key with inflection)

Important used String Methods
preg_replace_array
Str::after
Str::ascii
Str::before
Str::beforeLast()
Str::between
Str::betweenFirst
Str::contains()
Str::camel
Str::containsAll()
Str::endsWith()
Str::finish()
Str::headline()
Str::inlineMarkdown()
Str::is()
Str::isAscii()
Str::kebab()
Str::lcfirst()
Str::isJson()
Str::length()
Str::limit()
Str::lower()
Str::markdown()
Str::mask
Str::padBoth()
Str::pluralStudly(
Str::remove()
Str::replace()
Str::replaceArray()
Str::replaceFirst()
Str::replaceLast()
Str::reverse()
Str::slug()
Str::start()
Str::substr()
Str::substrCount()
Str::substrReplace()
Str::swap
Str::toHtmlString()
Str::ucfirst()
Str::ucsplit()
Str::upper()
Str::wordCount()
Str::words()
str()

Troubleshooting query
https://www.nicesnippets.com/blog/how-to-remove-space-from-string-in-laravel
how-to-remove-space-from-string-in-laravel

Image description

Image description

*now, i have to remove space *
Image description

Image description

Image description

preg_replace_array()
The preg_replace_array function replaces a given pattern in the string sequentially using an array:

$string = 'The event will take place between :start and :end';

$replaced = preg_replace_array('/:[a-z_]+/', ['8:30', '9:00'], $string);

// The event will take place between 8:30 and 9:00
Enter fullscreen mode Exit fullscreen mode

Str::after()
The Str::after method returns everything after the given value in a string. The entire string will be returned if the value does not exist within the string:

use Illuminate\Support\Str;

$slice = Str::after('This is my name', 'This is');

// ' my name'
Enter fullscreen mode Exit fullscreen mode

Str::afterLast()
The Str::afterLast method returns everything after the last occurrence of the given value in a string. The entire string will be returned if the value does not exist within the string:

use Illuminate\Support\Str;

$slice = Str::afterLast('App\Http\Controllers\Controller', '\\');

// 'Controller'
Enter fullscreen mode Exit fullscreen mode

Str::ascii()
The Str::ascii method will attempt to transliterate the string into an ASCII value:

use Illuminate\Support\Str;

$slice = Str::ascii('û');

Enter fullscreen mode Exit fullscreen mode

// 'u'

Str::before()
The Str::before method returns everything before the given value in a string:

use Illuminate\Support\Str;

$slice = Str::before('This is my name', 'my name');

// 'This is '
Enter fullscreen mode Exit fullscreen mode

Str::beforeLast()
The Str::beforeLast method returns everything before the last occurrence of the given value in a string:

use Illuminate\Support\Str;

$slice = Str::beforeLast('This is my name', 'is');

// 'This '
Enter fullscreen mode Exit fullscreen mode

Str::between()
The Str::between method returns the portion of a string between two values:

use Illuminate\Support\Str;

$slice = Str::between('This is my name', 'This', 'name');

// ' is my 
Enter fullscreen mode Exit fullscreen mode

'

Str::betweenFirst()
The Str::betweenFirst method returns the smallest possible portion of a string between two values:

use Illuminate\Support\Str;

$slice = Str::betweenFirst('[a] bc [d]', '[', ']');

// 'a
Enter fullscreen mode Exit fullscreen mode

'

Str::camel()
The Str::camel method converts the given string to camelCase:

use Illuminate\Support\Str;

$converted = Str::camel('foo_bar');

// fooBar
Enter fullscreen mode Exit fullscreen mode

Str::contains()
The Str::contains method determines if the given string contains the given value. This method is case sensitive:

use Illuminate\Support\Str;

$contains = Str::contains('This is my name', 'my');

// true
Enter fullscreen mode Exit fullscreen mode

You may also pass an array of values to determine if the given string contains any of the values in the array:

use Illuminate\Support\Str;

$contains = Str::contains('This is my name', ['my', 'foo']);

// true
Enter fullscreen mode Exit fullscreen mode

Str::containsAll()
The Str::containsAll method determines if the given string contains all of the values in a given array:

use Illuminate\Support\Str;

$containsAll = Str::containsAll('This is my name', ['my', 'name']);

// true
Enter fullscreen mode Exit fullscreen mode

Str::endsWith()
The Str::endsWith method determines if the given string ends with the given value:

use Illuminate\Support\Str;

$result = Str::endsWith('This is my name', 'name');

// true
Enter fullscreen mode Exit fullscreen mode

You may also pass an array of values to determine if the given string ends with any of the values in the array:

use Illuminate\Support\Str;

$result = Str::endsWith('This is my name', ['name', 'foo']);

// true

$result = Str::endsWith('This is my name', ['this', 'foo']);

// false
Enter fullscreen mode Exit fullscreen mode

Str::excerpt()
The Str::excerpt method extracts an excerpt from a given string that matches the first instance of a phrase within that string:

use Illuminate\Support\Str;

$excerpt = Str::excerpt('This is my name', 'my', [
    'radius' => 3
]);

// '...is my na...'
Enter fullscreen mode Exit fullscreen mode

The radius option, which defaults to 100, allows you to define the number of characters that should appear on each side of the truncated string.

In addition, you may use the omission option to define the string that will be prepended and appended to the truncated string:

use Illuminate\Support\Str;

$excerpt = Str::excerpt('This is my name', 'name', [
    'radius' => 3,
    'omission' => '(...) '
]);

// '(...) my name'
Enter fullscreen mode Exit fullscreen mode

Str::finish()
The Str::finish method adds a single instance of the given value to a string if it does not already end with that value:

use Illuminate\Support\Str;

$adjusted = Str::finish('this/string', '/');

// this/string/

$adjusted = Str::finish('this/string/', '/');

// this/string/
Enter fullscreen mode Exit fullscreen mode

Str::headline()
The Str::headline method will convert strings delimited by casing, hyphens, or underscores into a space delimited string with each word's first letter capitalized:

use Illuminate\Support\Str;

$headline = Str::headline('steve_jobs');

// Steve Jobs

$headline = Str::headline('EmailNotificationSent');

// Email Notification Sent
Enter fullscreen mode Exit fullscreen mode

Str::inlineMarkdown()
The Str::inlineMarkdown method converts GitHub flavored Markdown into inline HTML using CommonMark. However, unlike the markdown method, it does not wrap all generated HTML in a block-level element:

use Illuminate\Support\Str;

$html = Str::inlineMarkdown('**Laravel**');

// <strong>Laravel</strong>
Enter fullscreen mode Exit fullscreen mode

Str::is()
The Str::is method determines if a given string matches a given pattern. Asterisks may be used as wildcard values:

use Illuminate\Support\Str;

$matches = Str::is('foo*', 'foobar');

// true

$matches = Str::is('baz*', 'foobar');

// false
Enter fullscreen mode Exit fullscreen mode

Str::isAscii()
The Str::isAscii method determines if a given string is 7 bit ASCII:

use Illuminate\Support\Str;

$isAscii = Str::isAscii('Taylor');

// true

$isAscii = Str::isAscii('ü');

// false
Enter fullscreen mode Exit fullscreen mode

Str::isJson()
The Str::isJson method determines if the given string is valid JSON:

use Illuminate\Support\Str;

$result = Str::isJson('[1,2,3]');

// true

$result = Str::isJson('{"first": "John", "last": "Doe"}');

// true

$result = Str::isJson('{first: "John", last: "Doe"}');

// false
Enter fullscreen mode Exit fullscreen mode

Str::isUuid()
The Str::isUuid method determines if the given string is a valid UUID:

use Illuminate\Support\Str;

$isUuid = Str::isUuid('a0a2a2d2-0b87-4a18-83f2-2529882be2de');

// true

$isUuid = Str::isUuid('laravel');

// false
Enter fullscreen mode Exit fullscreen mode

Str::kebab()
The Str::kebab method converts the given string to kebab-case:

use Illuminate\Support\Str;

$converted = Str::kebab('fooBar');

// foo-bar
Enter fullscreen mode Exit fullscreen mode

Str::lcfirst()
The Str::lcfirst method returns the given string with the first character lowercased:

use Illuminate\Support\Str;

$string = Str::lcfirst('Foo Bar');

// foo Bar
Enter fullscreen mode Exit fullscreen mode

Str::length()
The Str::length method returns the length of the given string:

use Illuminate\Support\Str;

$length = Str::length('Laravel');

// 7
Enter fullscreen mode Exit fullscreen mode

Str::limit()
The Str::limit method truncates the given string to the specified length:

use Illuminate\Support\Str;

$truncated = Str::limit('The quick brown fox jumps over the lazy dog', 20);

// The quick brown fox...
Enter fullscreen mode Exit fullscreen mode

You may pass a third argument to the method to change the string that will be appended to the end of the truncated string:

use Illuminate\Support\Str;

$truncated = Str::limit('The quick brown fox jumps over the lazy dog', 20, ' (...)');

// The quick brown fox (...)
Enter fullscreen mode Exit fullscreen mode

Str::lower()
The Str::lower method converts the given string to lowercase:

use Illuminate\Support\Str;

$converted = Str::lower('LARAVEL');

// laravel
Enter fullscreen mode Exit fullscreen mode

Str::markdown()
The Str::markdown method converts GitHub flavored Markdown into HTML using CommonMark:

use Illuminate\Support\Str;

$html = Str::markdown('# Laravel');

// <h1>Laravel</h1>

$html = Str::markdown('# Taylor <b>Otwell</b>', [
    'html_input' => 'strip',
]);

// <h1>Taylor Otwell</h1>
Enter fullscreen mode Exit fullscreen mode

Str::mask()
The Str::mask method masks a portion of a string with a repeated character, and may be used to obfuscate segments of strings such as email addresses and phone numbers:

use Illuminate\Support\Str;

$string = Str::mask('taylor@example.com', '*', 3);

// tay***************
Enter fullscreen mode Exit fullscreen mode

If needed, you provide a negative number as the third argument to the mask method, which will instruct the method to begin masking at the given distance from the end of the string:

$string = Str::mask('taylor@example.com', '*', -15, 3);

// tay***@example.com
Enter fullscreen mode Exit fullscreen mode

Str::orderedUuid()
The Str::orderedUuid method generates a "timestamp first" UUID that may be efficiently stored in an indexed database column. Each UUID that is generated using this method will be sorted after UUIDs previously generated using the method:

use Illuminate\Support\Str;

return (string) Str::orderedUuid();
Enter fullscreen mode Exit fullscreen mode

Str::padBoth()
The Str::padBoth method wraps PHP's str_pad function, padding both sides of a string with another string until the final string reaches a desired length:

use Illuminate\Support\Str;

$padded = Str::padBoth('James', 10, '_');

// '__James___'

$padded = Str::padBoth('James', 10);

// '  James  
Enter fullscreen mode Exit fullscreen mode

'

Str::padLeft()
The Str::padLeft method wraps PHP's str_pad function, padding the left side of a string with another string until the final string reaches a desired length:

use Illuminate\Support\Str;

$padded = Str::padLeft('James', 10, '-=');

// '-=-=-James'

$padded = Str::padLeft('James', 10);

// '     James'
Enter fullscreen mode Exit fullscreen mode

Str::padRight()
The Str::padRight method wraps PHP's str_pad function, padding the right side of a string with another string until the final string reaches a desired length:

use Illuminate\Support\Str;

$padded = Str::padRight('James', 10, '-');

// 'James-----'

$padded = Str::padRight('James', 10);

// 'James  
Enter fullscreen mode Exit fullscreen mode

'

Str::plural()
The Str::plural method converts a singular word string to its plural form. This function supports any of the languages support by Laravel's pluralizer:

use Illuminate\Support\Str;

$plural = Str::plural('car');

// cars

$plural = Str::plural('child');

// children
Enter fullscreen mode Exit fullscreen mode

You may provide an integer as a second argument to the function to retrieve the singular or plural form of the string:

use Illuminate\Support\Str;

$plural = Str::plural('child', 2);

// children

$singular = Str::plural('child', 1);

// child
Enter fullscreen mode Exit fullscreen mode

Str::pluralStudly()
The Str::pluralStudly method converts a singular word string formatted in studly caps case to its plural form. This function supports any of the languages support by Laravel's pluralizer:

use Illuminate\Support\Str;

$plural = Str::pluralStudly('VerifiedHuman');

// VerifiedHumans

$plural = Str::pluralStudly('UserFeedback');

// UserFeedback
Enter fullscreen mode Exit fullscreen mode

You may provide an integer as a second argument to the function to retrieve the singular or plural form of the string:

use Illuminate\Support\Str;

$plural = Str::pluralStudly('VerifiedHuman', 2);

// VerifiedHumans

$singular = Str::pluralStudly('VerifiedHuman', 1);

// VerifiedHuman
Enter fullscreen mode Exit fullscreen mode

Str::random()
The Str::random method generates a random string of the specified length. This function uses PHP's random_bytes function:

use Illuminate\Support\Str;

$random = Str::random(40);
Enter fullscreen mode Exit fullscreen mode

Str::remove()
The Str::remove method removes the given value or array of values from the string:

use Illuminate\Support\Str;

$string = 'Peter Piper picked a peck of pickled peppers.';

$removed = Str::remove('e', $string);

// Ptr Pipr pickd a pck of pickld ppprs.
Enter fullscreen mode Exit fullscreen mode

You may also pass false as a third argument to the remove method to ignore case when removing strings.

Str::replace()
The Str::replace method replaces a given string within the string:

use Illuminate\Support\Str;

$string = 'Laravel 8.x';

$replaced = Str::replace('8.x', '9.x', $string);

// Laravel 9.x
Enter fullscreen mode Exit fullscreen mode

Str::replaceArray()
The Str::replaceArray method replaces a given value in the string sequentially using an array:

use Illuminate\Support\Str;

$string = 'The event will take place between ? and ?';

$replaced = Str::replaceArray('?', ['8:30', '9:00'], $string);

// The event will take place between 8:30 and 9:00
Enter fullscreen mode Exit fullscreen mode

Str::replaceFirst()
The Str::replaceFirst method replaces the first occurrence of a given value in a string:

use Illuminate\Support\Str;

$replaced = Str::replaceFirst('the', 'a', 'the quick brown fox jumps over the lazy dog');
Enter fullscreen mode Exit fullscreen mode

// a quick brown fox jumps over the lazy dog

Str::replaceLast()
The Str::replaceLast method replaces the last occurrence of a given value in a string:

use Illuminate\Support\Str;

$replaced = Str::replaceLast('the', 'a', 'the quick brown fox jumps over the lazy dog');

// the quick brown fox jumps over a lazy dog
Enter fullscreen mode Exit fullscreen mode

Str::reverse()
The Str::reverse method reverses the given string:

use Illuminate\Support\Str;

$reversed = Str::reverse('Hello World');

// dlroW olleH
Enter fullscreen mode Exit fullscreen mode

Str::singular()
The Str::singular method converts a string to its singular form. This function supports any of the languages support by Laravel's pluralizer:

use Illuminate\Support\Str;

$singular = Str::singular('cars');

// car

$singular = Str::singular('children');

// child
Enter fullscreen mode Exit fullscreen mode

Str::slug()
The Str::slug method generates a URL friendly "slug" from the given string:

use Illuminate\Support\Str;

$slug = Str::slug('Laravel 5 Framework', '-');


// laravel-5-framework
Enter fullscreen mode Exit fullscreen mode

Image description
Str::snake()
The Str::snake method converts the given string to snake_case:

use Illuminate\Support\Str;

$converted = Str::snake('fooBar');

// foo_bar

$converted = Str::snake('fooBar', '-');

// foo-bar
Enter fullscreen mode Exit fullscreen mode

Str::squish()
The Str::squish method removes all extraneous white space from a string, including extraneous white space between words:

use Illuminate\Support\Str;

$string = Str::squish('    laravel    framework    ');

// laravel framework
Enter fullscreen mode Exit fullscreen mode

Str::start()
The Str::start method adds a single instance of the given value to a string if it does not already start with that value:

use Illuminate\Support\Str;

$adjusted = Str::start('this/string', '/');

// /this/string

$adjusted = Str::start('/this/string', '/');

// /this/string
Enter fullscreen mode Exit fullscreen mode

Str::startsWith()
The Str::startsWith method determines if the given string begins with the given value:

use Illuminate\Support\Str;

$result = Str::startsWith('This is my name', 'This');

// true
Enter fullscreen mode Exit fullscreen mode

If an array of possible values is passed, the startsWith method will return true if the string begins with any of the given values:

$result = Str::startsWith('This is my name', ['This', 'That', 'There']);

// true
Enter fullscreen mode Exit fullscreen mode

Str::studly()
The Str::studly method converts the given string to StudlyCase:

use Illuminate\Support\Str;

$converted = Str::studly('foo_bar');

// FooBar
Enter fullscreen mode Exit fullscreen mode

Str::substr()
The Str::substr method returns the portion of string specified by the start and length parameters:

use Illuminate\Support\Str;

$converted = Str::substr('The Laravel Framework', 4, 7);

// Laravel
Enter fullscreen mode Exit fullscreen mode

Str::substrCount()
The Str::substrCount method returns the number of occurrences of a given value in the given string:

use Illuminate\Support\Str;

$count = Str::substrCount('If you like ice cream, you will like snow cones.', 'like');

// 2
Enter fullscreen mode Exit fullscreen mode

Str::substrReplace()
The Str::substrReplace method replaces text within a portion of a string, starting at the position specified by the third argument and replacing the number of characters specified by the fourth argument. Passing 0 to the method's fourth argument will insert the string at the specified position without replacing any of the existing characters in the string:

use Illuminate\Support\Str;

$result = Str::substrReplace('1300', ':', 2);
// 13:

$result = Str::substrReplace('1300', ':', 2, 0);
// 13:00
Enter fullscreen mode Exit fullscreen mode

Str::swap()
The Str::swap method replaces multiple values in the given string using PHP's strtr function:

use Illuminate\Support\Str;

$string = Str::swap([
    'Tacos' => 'Burritos',
    'great' => 'fantastic',
], 'Tacos are great!');
Enter fullscreen mode Exit fullscreen mode

// Burritos are fantastic!

Str::title()
The Str::title method converts the given string to Title Case:

use Illuminate\Support\Str;

$converted = Str::title('a nice title uses the correct case');
Enter fullscreen mode Exit fullscreen mode

// A Nice Title Uses The Correct Case

Str::toHtmlString()
The Str::toHtmlString method converts the string instance to an instance of Illuminate\Support\HtmlString, which may be displayed in Blade templates:

use Illuminate\Support\Str;

$htmlString = Str::of('Nuno Maduro')->toHtmlString();
Enter fullscreen mode Exit fullscreen mode

Str::ucfirst()
The Str::ucfirst method returns the given string with the first character capitalized:

use Illuminate\Support\Str;

$string = Str::ucfirst('foo bar');

// Foo bar
Enter fullscreen mode Exit fullscreen mode

Str::ucsplit()
The Str::ucsplit method splits the given string into an array by uppercase characters:

use Illuminate\Support\Str;

$segments = Str::ucsplit('FooBar');

// [0 => 'Foo', 1 => 'Bar']
Enter fullscreen mode Exit fullscreen mode

Str::upper()
The Str::upper method converts the given string to uppercase:

use Illuminate\Support\Str;

$string = Str::upper('laravel');

// LARAVEL
Enter fullscreen mode Exit fullscreen mode

Str::ulid()
The Str::ulid method generates a ULID:

use Illuminate\Support\Str;

return (string) Str::ulid();

// 01gd6r360bp37zj17nxb55yv40
Enter fullscreen mode Exit fullscreen mode

Str::uuid()
The Str::uuid method generates a UUID (version 4):

use Illuminate\Support\Str;

return (string) Str::uuid();
Enter fullscreen mode Exit fullscreen mode

Str::wordCount()
The Str::wordCount method returns the number of words that a string contains:

use Illuminate\Support\Str;

Str::wordCount('Hello, world!'); // 2
Enter fullscreen mode Exit fullscreen mode

Str::words()
The Str::words method limits the number of words in a string. An additional string may be passed to this method via its third argument to specify which string should be appended to the end of the truncated string:

use Illuminate\Support\Str;

return Str::words('Perfectly balanced, as all things should be.', 3, ' >>>');

// Perfectly balanced, as >>>
Enter fullscreen mode Exit fullscreen mode

str()
The str function returns a new Illuminate\Support\Stringable instance of the given string. This function is equivalent to the Str::of method:

$string = str('Taylor')->append(' Otwell');

// 'Taylor Otwell'
Enter fullscreen mode Exit fullscreen mode

If no argument is provided to the str function, the function returns an instance of Illuminate\Support\Str:

$snake = str()->snake('FooBar');

// 'foo_bar
Enter fullscreen mode Exit fullscreen mode

'

trans()
The trans function translates the given translation key using your localization files:

echo trans('messages.welcome');
Enter fullscreen mode Exit fullscreen mode

If the specified translation key does not exist, the trans function will return the given key. So, using the example above, the trans function would return messages.welcome if the translation key does not exist.

trans_choice()
The trans_choice function translates the given translation key with inflection:

echo trans_choice('messages.notifications', $unreadCount);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)