livewire-filemanager/filemanager
Livewire Filemanager is a simple, friendly file manager for Laravel. Manage files and folders with drag & drop, search, dark mode, multiple languages, and API endpoints. Built on Livewire and Spatie Media Library for seamless integration.
Installation:
composer require livewire-filemanager/filemanager
php artisan vendor:publish --tag=livewire-filemanager-migrations
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-migrations"
php artisan migrate
Basic Integration: Add the component and scripts to your blade template:
@filemanagerStyles
<x-livewire-filemanager />
@filemanagerScripts
First Use Case:
<img src="copied-url">).<x-livewire-filemanager /> component props (e.g., root-path, allowed-mime-types) in the source code./api/filemanager/v1/ for programmatic access (e.g., POST /folders to create a new folder).public function mount() {
$this->filemanagerRootPath = 'uploads';
}
public function save() {
$this->validate(['file_path' => 'required']);
$this->model->update(['image_path' => $this->file_path]);
}
// In your Livewire component
public function mount() {
$this->rootPath = auth()->user()->folder_path; // e.g., 'users/{id}/documents'
}
Route::middleware(['auth', 'can:access-filemanager'])->get('/filemanager', FilemanagerComponent::class);
# Create a folder via API
curl -X POST -H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{"name":"reports", "path":"documents"}' \
http://your-app.test/api/filemanager/v1/folders
$folder = Cache::remember("filemanager:folder:{$id}", now()->addHours(1), function() use ($id) {
return \LivewireFilemanager\Filemanager\Http\Requests\FolderRequest::find($id);
});
// In your FileController or Livewire component
public function handleUpload() {
$file = $this->uploadFile();
Thumbnail::dispatch($file)->delay(now()->addSeconds(10));
}
.env:
QUEUE_CONNECTION=database
public function mount() {
$this->rootPath = "tenants/{$this->tenant->id}/uploads";
}
use LivewireFilemanager\Filemanager\Traits\TenantAware;
class TenantFilemanager extends Filemanager {
use TenantAware;
}
php artisan vendor:publish --tag=livewire-filemanager-views
resources/views/vendor/livewire-filemanager/ files to match your app’s design system (e.g., replace Tailwind classes with your CSS variables).// resources/js/filemanager-extensions.js
document.addEventListener('livewire-filemanager-initialized', () => {
Livewire.hook('filemanager.context-menu', (menu) => {
menu.addItem('custom-action', 'Custom Action', () => {
alert('Triggered!');
});
});
});
@filemanagerScripts
<script src="{{ asset('js/filemanager-extensions.js') }}"></script>
use LivewireFilemanager\Filemanager\Facades\Filemanager;
// Upload a file programmatically
$file = Filemanager::upload('path/to/file.jpg', 'uploads/');
// Delete a file
Filemanager::delete($file->path);
Queue Configuration for Thumbnails:
QUEUE_CONNECTION is not configured (e.g., set to sync), thumbnails will block the request.QUEUE_CONNECTION=database in .env and run the queue worker:
php artisan queue:work
supervisor) to avoid blocking HTTP requests.HTTPS Requirement for File URLs:
FileController:
public function show($path) {
return response()->file(storage_path('app/' . $path));
// Or use a custom URL generator:
// return response()->file(url("https://your-app.test/storage/{$path}"));
}
Permission Denied Errors:
media_model in spatie/medialibrary is set to LivewireFilemanager\Filemanager\Models\Media.// config/medialibrary.php
'media_model' => \LivewireFilemanager\Filemanager\Models\Media::class,
Gate::define('delete-file', function ($user, $file) {
return $user->id === $file->owner_id;
});
Tailwind CSS in Production:
@filemanagerStyles directive includes Tailwind’s Play CDN, which is not suitable for production.// tailwind.config.js
module.exports = {
content: [
'./resources/**/*.blade.php',
'./vendor/livewire-filemanager/filemanager/resources/views/**/*.blade.php',
],
};
npm run production
Large File Uploads:
upload_max_filesize and post_max_size may limit file uploads.php.ini or use chunked uploads:
// In your Livewire component
public function mount() {
$this->maxFileSize = 10 * 1024 * 1024; // 10MB
}
chunked-upload middleware for files > 100MB.Log File Operations:
// In a service provider
\Spatie\MediaLibrary\MediaEvents::save(function ($model, $path) {
\Log::info("File uploaded: {$path}", ['model' => $model]);
});
Check Queue Jobs:
php artisan queue:failed-table
php artisan queue:work --once
Verify Folder Structure:
How can I help you explore Laravel packages today?