Create new helper

  1. Create a helpers.php inside app folder as like app\helpers.php
  2. Open composer.json file. Add app\helpers.php inside autoload object with a file object. As like below:
    "autoload": {
    
       "files": [
    
          "app/helpers.php"
    
       ],
    
       "classmap": [
    
          "database/seeds",
    
          "database/factories"
    
       ],
    
       "psr-4": {
    
          "App\\": "app/"
    
       }
    
    },
    
  3. Write your helper functions inside helpers.php as like below
    if (! function_exists('excerpt')) {
    function excerpt($string) {
    if(strlen($string)<25)
    return $string;
    else
    return substr($string, 0, 22).'...';
    }
    }
  4. Run the following command:
        composer dumpautoload
    

Labels: ,

© copyright-2020 Rejaul