Helper Function Example in Laravel 8

Websolutionstuff | Jun-22-2021 | Categories : Laravel

Hello All,

In this post we will see helper function example in laravel, Laravel provide in-buit global "helper" PHP functions and these functions are used by the laravel framework itself.

Here i will show laravel 8 global helper function with differnt type of example and also we will see how to use global helper function in laravel 8.

 

Exmaple : 

bcrypt() :  This function through 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 execution of the script.

dd($value);

 

now () : This function return current time.

$time = now();

 

Str::between : This method returns the part of a string between two values. if we need to use 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 string into camelcase.

use Illuminate\Support\Str;

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

// helloAll

 

Str::contains: This method check 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 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

 

Recommended Post
Featured Post
Laravel 8 Inner Join Query Example
Laravel 8 Inner Join Query Exa...

In this tutorial we will learn about laravel 8 inner join query example. Also see how to join two tables in laravel 8. I...

Read More

Nov-24-2021

MilesWeb Review: Why Go for Its Shared Hosting?
MilesWeb Review: Why Go for It...

For finding the right web hosting provider, you need to do a lot of research. There are hundreds of web hosting provider...

Read More

Nov-12-2021

How to Send Bulk Mail Using Queue in Laravel 9
How to Send Bulk Mail Using Qu...

In this article, we will see how to send bulk mail using queue in laravel 9. Laravel queue is used for sending bulk...

Read More

Mar-15-2022

Laravel 8 Yajra Datatable Example Tutorial
Laravel 8 Yajra Datatable Exam...

In this article, we will see the laravel 8 yajra datatable example tutorial. Datatable provides users to many...

Read More

Sep-30-2020