Static Assets

Static assets include all publicly accessible files inside the public directory. This typically covers uploaded files as well as JavaScript, CSS, images, fonts, and other front-end resources.

To generate URLs for static assets, use the asset global helper inside your templates:


<img src="{% asset('uploads/avatar.jpeg') %}" />

<script src="{% asset('js/main.js') %}"></script>
    

The asset helper automatically generates the correct URL based on your static assets route configuration. For example:


http://localhost:8888/static/uploads/avatar.jpeg

http://localhost:8888/static/js/main.js
    

The helper resolves files directly from the public directory. It can also be used outside templates, such as inside controllers or other application layers, whenever a public asset URL is required.

Configuring the Static Assets Route

The static assets route can be customized from your configuration file:


/**
 * Static assets route's path.
 */
'static_assets_route' => env('STATIC_ASSETS_ROUTE', 'static/'),
    

For security reasons, it is strongly recommended to restrict access to specific directories using proper server permissions and access control rules, depending on your server configuration.

Back to top