Create Helper Function In Laravel 8

In this article, we will see create helper function in laravel 8, Laravel provides in-built global "helper" PHP functions, and these functions are used by the laravel framework itself. Here we will see the laravel 8 global helper function with different types of examples and also we will see how to use the global helper function in laravel 8.

So, let's see laravel 8 create helper function, how to create helper function in laravel 8, how to create a custom helper in laravel 8, helper function in laravel 8, laravel 8 global functions, laravel 8 helper functions, create a common function in laravel.


bcrypt():  This function through which you can convert your password into bcrypt.

$pwd = bcrypt('password');



cookie(): The cookie function creates a new cookie instance.

$cookie = cookie('name', 'value', $minutes);


 csrf_field(): This function generates an HTML hidden input field containing the value of the CSRF token.

{{ csrf_field() }}


csrf_token(): This function retrieves the value of the current CSRF token.

$token = csrf_token();


dd():  This function dumps the given variables and ends the execution of the script.




now (): This function returns the current time.

$time = now();


Str::between: This method returns the part of a string between two values. if we need to use the str function then we need to add Illuminate\Support\Str class.

use Illuminate\Support\Str;

$slice = Str::between('This is demo example', 'This', 'example');

// it will return ' is demo '


Str::camel: This method converts the string into a camelcase.

use Illuminate\Support\Str;

$example = Str::camel('hello_all');

// helloAll


Str::contains: This method checks if the given string contains the given value, it is case sensitive.

use Illuminate\Support\Str;

$contains = Str::contains('This is demo example', 'demo');

// true



Arr::random: This method returns a random value from an array if we need to use the str function then we need to add use Illuminate\Support\Arr  class.

use Illuminate\Support\Arr;

$array = [1, 2, 3, 4, 5];

$random = Arr::random($array);

// 2 - it will return random number


You might also like :


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.