
Laravel Media Library
Laravel makes it very easy to manage files – this package makes a tiny bit easier.
📟 File sharing
Share public and private files with anyone. Comes with a basic and elegant UI.
❤ Eloquent models
Associate any file types with Eloquent models. Can also define assiociation at an attribute level with in-built object and array casts.
📜 Simple APIs
Exposed API endpoints and classes to easily integrate with any application.
📁 Directory system
A directory system and namespacing for more structured storage and visualisating files.
🔒 Secure
Public, signed, and protected endpoints for file sharing and downloads regardless of storage disks or permissions.
💪 Flexible
Configure middleware for the whole package routes or per API endpoints for fine-grained permissions and authorization.
This package is intended to provide most media related needs for any Laravel application. File uploads or attachments may be associated with any Eloquent model.
# Example Usage
Assuming files content has already been uploaded and a pending attachments has been created.
# Associate files
use MOIREI\MediaLibrary\Models\File;
...
[$file1, $file2] = File::take(2)->get();
$product = Product::find(1);
$product->attachFiles([$file1, $file2]);
# Use in attribute fields
During create
$product = Product::create([
'MOIREI MP202+',
'image' => $file1,
'gallery' => [$file1, $file2],
'description' => $richtext, // rich text content with <img src=".." /> attachment urls
]);
During update
$product = Product::find(1);
$product->image = $file;
$product->save();
...
$product->update([
'gallery' => [$file1],
]);