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

前端 未结 2 516
春和景丽
春和景丽 2020-12-18 23:48

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

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

In Laravel I could do

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


        
2条回答
  •  旧巷少年郎
    2020-12-19 00:30

    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);
        }
    }
    

提交回复
热议问题