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

3

13

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?

Agamic answered 15/5, 2015 at 1:29 Comment(0)
P
11

Have look at Lumen UrlGenerator source code, the Lumen framework supports just url and route helpers. Of course, you can write the asset helper if you want.

Preamplifier answered 15/5, 2015 at 2:19 Comment(0)
M
16

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);
    }
}
Martinelli answered 20/4, 2016 at 16:53 Comment(2)
how and where I add this file to lumen?Faddish
You can create an asset helper through creating your own php file with the methods included. Then, in composer, add this: { "autoload": { "files": [ "path/to/helpers.php" ] } }Vevina
P
11

Have look at Lumen UrlGenerator source code, the Lumen framework supports just url and route helpers. Of course, you can write the asset helper if you want.

Preamplifier answered 15/5, 2015 at 2:19 Comment(0)
I
2

Had the same problem. Turns out Lumen has a singleton method for handling such. Just use:

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

or For handling routes

{{ URL::route('home') }}
Intercross answered 25/6, 2022 at 15:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.