Add “files” in composer.json:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
{ "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": { "php": ">=5.6.4", "laravel/framework": "5.3.*" }, "require-dev": { "fzaninotto/faker": "~1.4", "mockery/mockery": "0.9.*", "phpunit/phpunit": "~5.0", "symfony/css-selector": "3.1.*", "symfony/dom-crawler": "3.1.*" }, "autoload": { "classmap": [ "database" ], "psr-4": { "App\\": "app/" }, "files":[ "app/Helpers/helper.php" ] }, "autoload-dev": { "classmap": [ "tests/TestCase.php" ] }, "scripts": { "post-root-package-install": [ "php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "php artisan key:generate" ], "post-install-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postInstall", "php artisan optimize" ], "post-update-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postUpdate", "php artisan optimize" ] }, "config": { "preferred-install": "dist", "sort-packages": true } } |
Update autoload.php
1 |
$ composer dump-autoload |
Custom Helper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
<?php use Carbon\Carbon; if(!function_exists('logg')) { function logg($value, $stop=true) { if(is_array($value) == true || is_object($value) == true) { print "<pre>"; print_r($value); print "<pre>"; } else { echo var_dump($value); } if($stop == true) { exit(); } } } if(!function_exists('val')){ function val($object, $key, $default_value=''){ if(isset($object) == false){ return $default_value; } if(is_object($object) == true){ if(isset($object->{$key}) == true){ return $object->{$key}; }else{ return $default_value; } } if(is_array($object) == true){ if(isset($object[$key]) == true){ return $object[$key]; }else{ return $default_value; } } } } if ( ! function_exists('show_alert')) { function show_alert($msg, $url='') { echo '<html><head><meta charset="UTF-8">'; echo '<script>alert("' . $msg . '");'; if($url != '' && strlen($url) > 0){ echo 'window.location.href = "' . $url . '";'; }else{ echo 'window.history.back();'; } echo '</script>'; echo '</head><body></body></html>'; exit(); } } if ( ! function_exists('img_url')) { function img_url($file) { $file = str_replace('\\', '/', $file); $url = BASE_URL . 'storage/' . $file; return $url; } } if ( ! function_exists('std_date')) { function std_date($date) { return Carbon::parse($date)->format('Y/m/d'); } } if(!function_exists('go')){ function go($url){ header('location:' . $url); exit(); } } if(!function_exists('is_collection')){ function is_collection($data){ if($data instanceof Illuminate\Database\Eloquent\Collection){ return true; }else{ return false; } } } |
Reference: