Zero Database Bloat
Store simple file paths in standard string or JSON columns. No extra tables, no polymorphic joins, and no database migrations.
v1.3 • Laravel 11, 12, & 13
Automatic WebP optimization, center-cropping, chunked video streaming, and zero extra database tables. Upload files with one expressive line of code.
use App\Models\User;
use KaziOmar\SmartUpload\Facades\Upload;
// Resize to 300x300, convert to WebP, delete the old avatar from disk, and save
$result = Upload::file($request->file('avatar'))
->replace($user->avatar)
->fit(300, 300)
->save('avatars');
$user->update(['avatar' => $result->path]);use KaziOmar\SmartUpload\Facades\Upload;
// 1. Upload in the background when the user picks a file:
$temp = Upload::temp($request->file('avatar'));
// Returns: {"filename": "tmp_a8f9c1b2.jpg", "url": "..."}
// 2. Fast JSON submit when the user clicks 'Save Profile':
$final = Upload::fromTemp($request->string('avatar_token'))
->fit(300, 300)
->save('avatars');
$user->update(['avatar' => $final->path]);use KaziOmar\SmartUpload\Facades\Upload;
// Handles chunks 1, 2, 3... with zero memory buildup
$chunk = Upload::chunk($request);
if ($chunk->isComplete()) {
// Merges chunks directly on disk using PHP streams (~5MB RAM)
$video = $chunk->save('videos');
return response()->json(['path' => $video->path]);
}
return response()->json(['progress' => $chunk->progress()]);use Illuminate\Support\Facades\DB;
use KaziOmar\SmartUpload\Facades\Upload;
DB::transaction(function () use ($request) {
$receipt = Upload::file($request->file('receipt'))->save('receipts');
Invoice::create([
'receipt_path' => $receipt->path,
'total' => $request->total,
]);
// If payment fails and throws here, the uploaded file is
// automatically deleted from disk or S3. No ghost files!
PaymentService::charge();
});Why developers choose Smart Upload over bloated media packages or manual boilerplate.
| Feature | Native Laravel | Spatie MediaLibrary | Smart Upload |
|---|---|---|---|
| Extra database tables | None | 1–3 tables | None |
| API Style | Basic procedural | Coupled to models | Fluent chaining |
| WebP & Sizing | Manual GD code | Complex conversions | One-liner |
| Purge on DB rollback | No (files stay orphaned) | No | Automatic |
| Two-step SPA / Mobile | Build it yourself | Complex | Built-in (temp / fromTemp) |
| Video chunk streaming | Build it yourself | Not supported | Built-in |
| Clean up on model delete | Manual deletion code | Model events | Single Trait |
Install the package via Composer:
composer require thekaziomar/laravel-smart-uploadPublish the config file:
php artisan vendor:publish --tag=smart-upload-config