Friday, November 13, 2015

Including the file in auto load in Laravel 5

Create a new file called helpers.php in App folder and write the following helper functions

<?php
/** * Return sizes readable by humans */function human_filesize($bytes, $decimals = 2){    $size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];    $factor = floor((strlen($bytes) - 1) / 3);
    return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) .    @$size[$factor];}
/** * Is the mime type an image */function is_image($mimeType){    return starts_with($mimeType, 'image/');}

 In the autoload section of the composer.json file, add the following lines

"autoload": {
    "classmap": [
        "database"    ],
    "psr-4": {
        "App\\": "app/"    },
    "files": [
        "app/helpers.php"    ]

now go to cmd and write composer dumpauto to regenerate the autoload files. 

No comments:

Post a Comment