Coder Social home page Coder Social logo

helper-function-laravel-8's Introduction

Helper Function Example in Laravel 8

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.