Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do {{ asset('/css/app.css') }} in Lumen?

In Lumen, I can do this in my blade template:

{{ url('/css/app.css') }}

In Laravel I could do

{{ asset('/css/app.css') }}

Is the url helper all I have to work with in Lumen?

like image 223
prograhammer Avatar asked May 15 '15 01:05

prograhammer


1 Answers

Had the same problem, moving from laravel to lumen. As @hieu-le says, I made an asset helper as below.

if (!function_exists('urlGenerator')) {
    /**
     * @return \Laravel\Lumen\Routing\UrlGenerator
     */
    function urlGenerator() {
        return new \Laravel\Lumen\Routing\UrlGenerator(app());
    }
}

if (!function_exists('asset')) {
    /**
     * @param $path
     * @param bool $secured
     *
     * @return string
     */
    function asset($path, $secured = false) {
        return urlGenerator()->asset($path, $secured);
    }
}
like image 177
Murwa Avatar answered Sep 28 '22 04:09

Murwa