Javascript,Nodejs,MongodDB,WordPress,CSS,PHP

LightBlog

Monday, January 28, 2019

How to create helper in laravel

In this section we will see how to create a helper in laravel,create ahelpers.php file in your app folder and load it up with composer.
adding this in your composer.json file.

"autoload": {
    "classmap": [
        ...
    ],
    "psr-4": {
        "App\\": "app/"
    },
    "files": [
        "app/helpers.php" // <---- ADD THIS
    ]
},
 After adding that to your composer.json file, run the following command:

composer dump-autoload
 write pure function and it will be automatic in accessible anywhere in your blade file
in this example i have write a function for encrypt some string in middle of string as *
expample:
<?php

function get_enc_email($str) {
    $str_length = strlen($str);
    return substr($str, 0, 3).str_repeat('*', $str_length - 2).substr($str, $str_length - 10);
}
$my_string = 'example@yandex.com';
echo get_enc_email($my_string); //will give you output e******@yandex.com 

?> 

No comments:

Post a Comment