PHPackages                             litepie/filehub - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. litepie/filehub

ActiveLibrary[Image &amp; Media](/categories/media)

litepie/filehub
===============

Modern Laravel file and media management package with security, performance, and flexibility

v1.0.9(7mo ago)0472MITPHPPHP ^8.2

Since Aug 21Pushed 6mo agoCompare

[ Source](https://github.com/Litepie/Filehub)[ Packagist](https://packagist.org/packages/litepie/filehub)[ RSS](/packages/litepie-filehub/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (8)Versions (11)Used By (2)

FileHub - Laravel File Management Package
=========================================

[](#filehub---laravel-file-management-package)

A comprehensive file upload and management package for Laravel applications with support for polymorphic attachments, image processing, variant generation, user tracking, and document metadata.

Features
--------

[](#features)

- 📎 **Polymorphic File Attachments** - Attach files to any Eloquent model
- 🖼️ **Image Processing** - Automatic variant generation (thumbnails, different sizes)
- 🔒 **Security** - File validation, malware scanning, signature verification
- 📊 **User Tracking** - Track who uploaded what, when, and from where
- 📄 **Document Metadata** - Store titles, descriptions, document numbers, dates
- 🎯 **Collections** - Organize files into collections (avatars, documents, galleries)
- ⚡ **Queue Support** - Process image variants in background
- 🔐 **Upload Tokens** - Secure upload endpoints with temporary tokens
- 🌐 **URL Generation** - Signed URLs, temporary URLs, variant URLs
- 🗑️ **Soft Deletes** - Safe file deletion with recovery options

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require litepie/filehub
```

### 2. Publish Configuration

[](#2-publish-configuration)

```
php artisan vendor:publish --provider="Litepie\FileHub\Providers\FileHubServiceProvider"
```

### 3. Run Migrations

[](#3-run-migrations)

```
php artisan migrate
```

### 4. Configure Storage

[](#4-configure-storage)

Make sure your storage is properly configured in `config/filesystems.php`:

```
'disks' => [
    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],
],
```

Link storage:

```
php artisan storage:link
```

Configuration
-------------

[](#configuration)

The configuration file is published to `config/filehub.php`. Key settings include:

```
return [
    // Default storage disk
    'default_disk' => env('FILEHUB_DISK', 'public'),

    // Validation rules
    'validation' => [
        'max_size' => env('FILEHUB_MAX_SIZE', 10240), // KB
        'allowed_mimes' => [...],
        'forbidden_extensions' => ['exe', 'bat', ...],
    ],

    // Image processing
    'image_processing' => [
        'driver' => env('FILEHUB_IMAGE_DRIVER', 'gd'),
        'quality' => 85,
        'variants' => [
            'thumbnail' => ['width' => 150, 'height' => 150, 'method' => 'crop'],
            'small' => ['width' => 300, 'height' => 300],
            'medium' => ['width' => 600, 'height' => 600],
            'large' => ['width' => 1200, 'height' => 1200],
        ],
    ],

    // Security
    'security' => [
        'hash_filenames' => true,
        'file_signature_check' => true,
        'require_upload_token' => true,
    ],
];
```

Basic Usage
-----------

[](#basic-usage)

### Add Trait to Model

[](#add-trait-to-model)

```
use Litepie\FileHub\Traits\HasFileAttachments;

class Organization extends Model
{
    use HasFileAttachments;
}
```

### Upload Files

[](#upload-files)

```
// Single file upload
$organization = Organization::find(1);
$attachment = $organization->attachFile($request->file('logo'), 'logos');

// Multiple files
$attachments = $organization->attachFile($request->file('documents'), 'documents');

// With metadata
$attachment = $organization->attachFile($uploadedFile, 'licenses', [
    'document_type' => 'trade_license',
    'title' => 'Trade License',
    'description' => 'Company trade license document',
    'document_number' => 'TL-2025-001',
    'issue_date' => '2025-01-01',
    'expiry_date' => '2026-01-01',
]);
```

### Upload from URL or Path

[](#upload-from-url-or-path)

```
// From URL
$attachment = $organization->attachFromUrl(
    'https://example.com/document.pdf',
    'documents'
);

// From local path
$attachment = $organization->attachFromPath(
    storage_path('temp/file.pdf'),
    'documents'
);
```

### Retrieve Files

[](#retrieve-files)

```
// Get all attachments
$files = $organization->fileAttachments;

// Get by collection
$logos = $organization->getFileAttachments('logos');
$documents = $organization->getFileAttachments('documents');

// Get first/latest
$logo = $organization->getFirstFileAttachment('logos');
$latest = $organization->getLatestFileAttachment('documents');

// Check if has attachments
if ($organization->hasFileAttachments('logos')) {
    // ...
}

// Count attachments
$count = $organization->getFileAttachmentsCount('documents');
```

### Access File URLs

[](#access-file-urls)

```
$attachment = FileAttachment::find(1);

// Direct access (property)
echo $attachment->url;
echo $attachment->download_url;

// Method call with variant support
echo $attachment->url(); // Original
echo $attachment->url('thumbnail'); // Thumbnail variant
echo $attachment->url('medium'); // Medium variant

// Signed URLs (temporary)
$signedUrl = $attachment->getSignedUrl(3600); // 1 hour

// Variant URLs
$thumbnailUrl = $attachment->getVariantUrl('thumbnail');
```

### Delete Files

[](#delete-files)

```
// Delete single file
$organization->detachFile($attachmentId);

// Delete all files in a collection
$organization->detachAllFiles('documents');

// Delete all files
$organization->detachAllFiles();
```

Document Metadata
-----------------

[](#document-metadata)

FileHub supports rich document metadata:

```
$attachment = FileAttachment::create([
    'document_type' => 'letterhead',      // Document category
    'title' => 'Company Letterhead',      // Display title
    'description' => 'Official letterhead', // Detailed description
    'document_number' => 'LH-2025-001',   // Reference number
    'issue_date' => '2025-01-01',         // Issue/creation date
    'expiry_date' => '2026-01-01',        // Expiration date
]);

// Query by metadata
$licenses = FileAttachment::where('document_type', 'license')->get();
$expiringSoon = FileAttachment::where('expiry_date', '
