php - Laravel add http to urls -
is there helper in laravel 5.0 automatically adds http url without it? similar codeigniter's prep_url
found here.
no can add yourself. in composer.json
file add files key under autoload , point helper file e.g.
"autoload": { "files": [ "app/helpers.php" ] }
then create app/helpers.php
code (lifted https://github.com/bcit-ci/codeigniter/blob/master/system/helpers/url_helper.php):
<?php if ( ! function_exists('prep_url')) { /** * prep url * * adds http:// part if no scheme included * * @param string url * @return string */ function prep_url($str = '') { if ($str === 'http://' or $str === '') { return ''; } $url = parse_url($str); if ( ! $url or ! isset($url['scheme'])) { return 'http://'.$str; } return $str; } }
now have prep_url
globally accessible! don't forget run composer dump-autoload
too.
Comments
Post a Comment