Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Asset Helper

Asset Helper Laravel Package

spatie/asset-helper

Laravel 4 helper to generate URLs for revisioned/cache-busted assets. Given an original name like admin.css, it finds the hashed version in your public assets folder and returns a URL such as /assets/admin.0ce5cb43.css.

View on GitHub
Deep Wiki
Context7

Get the url to a revisioned asset

Frequently asked questions about Asset Helper
Does spatie/asset-helper work with Laravel 5.5+ or only Laravel 4?
This package is explicitly designed for Laravel 4 and may require manual adjustments for newer versions. For Laravel 5.5+, you’d need to create a custom facade or service provider to bridge compatibility gaps, as core Laravel methods (e.g., `Asset::getUrl()`) are deprecated or replaced by Laravel Mix/Vite’s built-in asset handling.
How do I install spatie/asset-helper in Laravel 4?
Run `composer require spatie/asset-helper`, then register the `AssetHelperServiceProvider` in `app/config/app.php` under the `providers` array. The package also includes a facade (`Asset`) for convenience, which should be added to the `aliases` array in the same file.
What if my asset pipeline already uses Laravel Mix or Vite for cache-busting?
If you’re using Laravel Mix or Vite, this package may be redundant since those tools generate `mix-manifest.json` or similar files to handle hashed assets automatically. Modern Laravel projects typically rely on `mix('css/admin.css')` or `Vite::asset('resources/css/admin.css')` instead of this helper.
Can I use this package for dynamic asset paths (e.g., user-uploaded files)?
No, this package is designed for static, pre-hashed assets in a single public folder. For dynamic assets like user uploads, consider alternatives like `spatie/laravel-medialibrary` or manually constructing URLs with `Storage::url()` and file hashing logic.
How does the package resolve hashed filenames like `admin.0ce5cb43.css`?
The package scans your public assets folder for filenames matching the logical name (e.g., `admin.css`) followed by a hash (e.g., `admin.0ce5cb43.css`). It returns the first match found, ensuring cache-busting via the hashed segment. This assumes your build pipeline appends hashes to filenames manually.
Is there a way to test if the package correctly resolves asset URLs?
Yes, you can test by verifying `Asset::getUrl('admin.css')` returns a URL with a hash (e.g., `/assets/admin.0ce5cb43.css`). Mock the public folder structure in tests or use file system assertions to confirm the correct hashed filename is detected. Check for edge cases like missing files or multiple matches.
What are the risks of using this package in production if it’s unmaintained?
The package hasn’t been updated since 2016, so it lacks security patches for Laravel 4’s deprecated core. Risks include compatibility issues with PHP 7.4+ or Laravel upgrades. If critical, consider forking the package or replacing it with modern alternatives like Laravel Mix’s manifest or Vite’s asset handling.
How do I handle assets stored in subfolders (e.g., `/assets/css/admin.css`)?
The package assumes a flat public folder structure. For subfolders, pass the full relative path (e.g., `Asset::getUrl('css/admin.css')`). Ensure your build pipeline mirrors this structure with hashed filenames (e.g., `/assets/css/admin.0ce5cb43.css`).
Are there alternatives to spatie/asset-helper for Laravel 5.5+?
For Laravel 5.5+, use Laravel Mix’s `mix()` helper or Vite’s `asset()` function, which automatically handle hashed filenames via `mix-manifest.json` or Vite’s build process. If you need a lightweight solution, manually append filemtime hashes (e.g., `asset('css/admin.css?v='.filemtime(public_path('css/admin.css')))`).
Does this package support HTTPS or CDN asset URLs?
No, the package generates relative URLs based on your public folder structure. For HTTPS or CDN support, manually prepend the base URL (e.g., `https://cdn.example.com`) to the output of `Asset::getUrl()`. Alternatively, configure your web server or Laravel’s `url()` helper to handle asset paths globally.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport