Call to undefined function asset() in Laravel lumen project

  laravel, lumen, php

I installed a fresh installation of laravel lumen

"laravel/lumen-framework": "^8.0"

created a controller that returns a view

public function register(){
        return view('register');
    }

view file

<link rel="stylesheet" type="text/css" href="{{asset('css/opensans-font.css')}}" />

im trying to use the asset function but it throws an undefined exception

Call to undefined function asset() (View: C:xampphtdocsraziresourcesviewsregister.blade.php)

i tried updating and reinstalling dependencies but it didn’t work
also checked the UrlGenerator and found the asset function and made sure it exists

/**
     * Generate a URL to an application asset.
     *
     * @param  string  $path
     * @param  bool|null  $secure
     * @return string
     */
    public function asset($path, $secure = null)
    {
        if ($this->isValidUrl($path)) {
            return $path;
        }

        // Once we get the root URL, we will check to see if it contains an index.php
        // file in the paths. If it does, we will remove it since it is not needed
        // for asset paths, but only for routes to endpoints in the application.
        $root = $this->getRootUrl($this->formatScheme($secure));

        return $this->removeIndex($root).'/'.trim($path, '/');
    }

Source: Laravel

Leave a Reply