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?

prograhammer
  • 20,132
  • 13
  • 91
  • 118

3 Answers3

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);
    }
}
Murwa
  • 2,238
  • 1
  • 20
  • 21
  • 4
    how and where I add this file to lumen? – Giacomo M Oct 15 '18 at 13:36
  • 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" ] } }``` – PatricNox Sep 29 '20 at 09:32
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.

Hieu Le
  • 8,288
  • 1
  • 34
  • 55
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') }}
mobfire
  • 19
  • 3