vish4395 / laravel-file-viewer
A basic file viewer for Laravel projects
Package info
github.com/vish4395/laravel-file-viewer
Language:JavaScript
pkg:composer/vish4395/laravel-file-viewer
Requires
- php: ^8.2
- illuminate/contracts: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0|^11.0
- phpunit/phpunit: ^11.0|^12.0
This package is auto-updated.
Last update: 2026-06-02 02:41:19 UTC
README
Laravel File Viewer is the easiest way to preview images, videos, audio, PDF, DOCX, PPTX, XLSX, CSV, and more in your Laravel app. Instantly add beautiful file previews to your admin panels, dashboards, or user portals — with zero configuration required.
✨ Loved by developers. Easy to install. Works out of the box.
🚦 Features
- 📄 Preview images, videos, audio, PDF, DOCX, PPTX, XLSX, CSV, plain text, JSON, and archives
- ⚡️ Super simple integration — one method call in your controller
- 🎨 Customizable UI — publish and tweak the views
- 🛡️ Secure: validates file existence via Laravel's storage disks; DOCX frame route uses signed URLs
- 🔧 Configurable toolbar (download, open in new tab, copy link, fullscreen)
- 🌍 Multilingual ready
- 🔌 Auto-discovered — no manual registration required in Laravel 11+
📋 Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
🛠️ Installation
Install via Composer:
composer require vish4395/laravel-file-viewer
Publish the assets (required):
php artisan vendor:publish --provider="Vish4395\LaravelFileViewer\LaravelFileViewerServiceProvider" --tag=assets
Publish the config (optional):
php artisan vendor:publish --provider="Vish4395\LaravelFileViewer\LaravelFileViewerServiceProvider" --tag=config
Publish views for UI customization (optional):
php artisan vendor:publish --provider="Vish4395\LaravelFileViewer\LaravelFileViewerServiceProvider" --tag=views
🚀 Quick Start
The package is auto-discovered in Laravel 11+. No manual provider or alias registration needed.
Example Controller
use Vish4395\LaravelFileViewer\LaravelFileViewer; class FilePreviewController extends Controller { public function show(string $fileName) { return LaravelFileViewer::show( fileName: $fileName, filePath: $fileName, fileUrl: asset('storage/' . $fileName), disk: 'public', fileData: [ ['label' => 'Uploaded by', 'value' => 'Jane Doe'], ['label' => 'Department', 'value' => 'Finance'], ] ); } }
Add a route in routes/web.php:
Route::get('/files/{fileName}', [FilePreviewController::class, 'show']);
LaravelFileViewer::show() Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
fileName |
string |
— | Display name for the file |
filePath |
string |
— | Path relative to the storage disk |
fileUrl |
string |
— | Public URL used to render the preview |
disk |
string|null |
'public' |
Laravel storage disk (overrides config default) |
fileData |
array |
[] |
Key/value pairs displayed in the details panel |
⚙️ Configuration
After publishing the config (config/laravel-file-viewer.php), you can customize behavior via environment variables or directly in the config file.
return [ // Default storage disk used when no disk is passed to ::show() 'default_disk' => env('FILE_VIEWER_DISK', 'public'), // Fall back to Google Docs Viewer for unsupported file types 'google_viewer_fallback' => env('FILE_VIEWER_GOOGLE_FALLBACK', false), // Toolbar button visibility 'toolbar' => [ 'download' => env('FILE_VIEWER_TOOLBAR_DOWNLOAD', true), 'open_in_new_tab' => env('FILE_VIEWER_TOOLBAR_NEW_TAB', true), 'copy_link' => env('FILE_VIEWER_TOOLBAR_COPY_LINK', true), 'fullscreen' => env('FILE_VIEWER_TOOLBAR_FULLSCREEN', true), ], ];
Environment Variables
| Variable | Default | Description |
|---|---|---|
FILE_VIEWER_DISK |
public |
Default storage disk |
FILE_VIEWER_GOOGLE_FALLBACK |
false |
Use Google Docs Viewer as fallback |
FILE_VIEWER_TOOLBAR_DOWNLOAD |
true |
Show download button |
FILE_VIEWER_TOOLBAR_NEW_TAB |
true |
Show "open in new tab" button |
FILE_VIEWER_TOOLBAR_COPY_LINK |
true |
Show copy link button |
FILE_VIEWER_TOOLBAR_FULLSCREEN |
true |
Show fullscreen button |
📂 Supported File Types
| Category | Types | Viewer |
|---|---|---|
| Images | JPEG, PNG, GIF, WebP, SVG, etc. | Native <img> |
| Video | MP4, WebM, OGG, etc. | Native <video> |
| Audio | MP3, WAV, OGG, etc. | Native <audio> |
.pdf |
Embedded PDF viewer | |
| Word | .docx, .doc |
docx-preview.js |
| Excel | .xlsx, .xls |
SheetJS |
| PowerPoint | .pptx, .ppt |
Office Online / iframe |
| CSV | .csv |
Inline table |
| Text | .txt, .log, .md, .json |
Syntax-highlighted text |
| Archives | .zip, .rar, .tar, .gz |
Details panel |
| Other | Any unsupported type | Office Online or Google Docs Viewer (if enabled) |
🌟 Why Laravel File Viewer?
- Save hours: No need to wire up multiple JS libraries yourself.
- Modern UI: Looks great out of the box with a consistent toolbar.
- Flexible: Works with any Laravel storage disk — local, S3, or custom.
- Trusted: Used in production by agencies and startups.
📈 Help Us Grow!
If you find this package useful:
- ⭐ Star this repo on GitHub
- 📦 Try it in your next Laravel project
- 🐦 Tweet about it @vish4395
- 💬 Share feedback and suggestions
📋 Changelog
See CHANGELOG for recent updates.
🤝 Contributing
PRs are welcome! See CONTRIBUTING for details. Questions? Email vishal@newai.in or open an issue.
🔒 Security
If you discover any security issues, please email vishal@newai.in instead of using the issue tracker.
👏 Credits
📄 License
MIT. See License File for details.
