daravel_medialibrary 1.25.0
daravel_medialibrary: ^1.25.0 copied to clipboard
Files and images attached to Daravel models, on spatie/laravel-medialibrary's media table and file layout, with image conversions in pure Dart.
daravel_medialibrary #
English · Bahasa Indonesia
Files and images attached to Daravel
models, the way spatie/laravel-medialibrary v11 does it: one media table,
collections, and image conversions made from the original. Rows and files
follow Spatie's layout, so a Laravel application on the same database and
disk shares them. Images are converted in pure Dart, with no GD or
ImageMagick to install.
dartisan pub:add media
import 'package:daravel_medialibrary/daravel_medialibrary.dart';
final class Post extends Model with InteractsWithMedia {
static final ModelDefinition<Post> definition = ModelDefinition<Post>(
table: 'posts',
factory: Post.new,
observers: [MediaObserver<Post>()],
);
@override
ModelDefinition<Post> get modelDefinition => Post.definition;
@override
void registerMediaCollections() => addMediaCollection('cover').singleFile();
@override
void registerMediaConversions([Media? media]) {
addMediaConversion('thumb').fit(Fit.crop, 300, 200).nonQueued();
}
}
final media = await post
.addMedia((await request.file('cover'))!)
.toMediaCollection('cover');
final thumb = await post.getFirstMediaUrl('cover', 'thumb');
- Spatie's
mediatable,<id>/<file>and<id>/conversions/<file>-<conversion>.jpg: Laravel and Daravel read, serve and delete each other's media. - Conversions with Spatie's resize rules (
width,height,fit,crop) in a separate isolate, JPEG by default, EXIF rotation applied; queued ones run as a job. - Single-file collections, accepted MIME types, size limit, and Spatie's
file name cleaning and refused extensions (
shell.php.jpg). media:regenerateandmedia:clean.
Documentation: https://github.com/daravel-dev/daravel/blob/main/docs/guide/medialibrary.md.
License and trademarks #
MIT. "Laravel" is a trademark of Laravel Holdings Inc.; "Dart" is a trademark of Google LLC. Daravel is an independent project, not affiliated with or endorsed by either.