Laravel

Laravel Important helpers functions

Laravel 7.2 routing with route group auth guard check with prefix

Laravel Important helpers functions

Hello to all, welcome to therichpost.com. In this post, I will tell you, Laravel Important helpers functions. Like I always say that laravel is the best Mvc php framework.

In this post, I will tell you some Laravel Important helpers functions and here are they:
optional()
The optional function accepts any argument and allows you to access properties or call methods on that object. If the given object is null, properties and methods will return null instead of causing an error:

$user = User::find(1);
return optional($user)->name;


str_slug()
The str_slug() function generates a URL friendly slug from the given string. You can use this function to create a slug for your post or product title.

$slug = str_slug('Laravel 5 Framework', '-');
// laravel-5-framework

route()
The route() function generates a route URL for a named route.
$url = route('login');

If the route accepts parameters, you can simply pass them in an array as the second argument.
$url = route('products', ['id' => 1]);

If you want to generate a relative URL rather than an absolute URL, you can pass false as the third argument.
$url = route('products', ['id' => 1], false);

str_plural()
The str_plural function converts a string to its plural form. This function currently only supports the English language:
$plural = str_plural('car');
// cars

$plural = str_plural('child');
// children


str_limit()
The str_limit function truncates the given string at the specified length:

$truncated = str_limit('The quick brown fox jumps over the lazy dog', 20);
// The quick brown fox...

You may also pass a third argument to change the string that will be appended to the end:
$truncated = str_limit('The quick brown fox jumps over the lazy dog', 20, ' (...)');
// The quick brown fox (...)

str_contains()
The str_contains function determines if the given string contains the given value (case sensitive):
$contains = str_contains('This is my name', 'my');

// true

 if you have any query related this post then please do ask.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10 Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.