Download the PHP package corollarium/modelarium-medialibrary without Composer
On this page you can find all versions of the php package corollarium/modelarium-medialibrary. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download corollarium/modelarium-medialibrary
More information about corollarium/modelarium-medialibrary
Files in corollarium/modelarium-medialibrary
Package modelarium-medialibrary
Short Description Integrates Spatie Laravel-media-library with Modelarium and GraphQL
License MIT
Homepage https://github.com/Corollarium/modelarium-medialibrary/
Informations about the package modelarium-medialibrary
Modelarium - Laravel Media Library package
This package integrates Spatie's Laravel Media Library to Modelarium, allowing GraphQL queries with LighthousePHP to easily access media on models.
Installing
On your Laravel app run:
Quick overview
This a Graphql file for a model with two different media collections, "image" and "map". Both have extra fields, "url" and "description". "Map" also has a conversion "thumb" with 150x150 (max, maintaining aspect ratio) thumbnails.
This will automatically generate roughly the following code on your model class:
Documentation
The @laravelMediaLibraryData
directive supports the following arguments:
TODO
FAQ
I need some custom conversion on my collection.
If the basic arguments on the directive are not enough, just override the method on your model class:
How do I get only the image url for a single image in my type?
Define a xxxUrl
on your type, where xxx
is your collection name. which is filled automatically by the attribute method on the model. Don't forget to add @migrationSkip
so it won't be created in the migration. Example:
your query will look like this:
How do I get the full image data in a query?
Just define the LaravelMediaLibraryData
field in your type. Example:
On your query, fetch the field
You can easily access only the first one too:
In your query:
I want a single image in the collection, never more than one. How do I do that?
Declare a singleFile
collection. Notice that the return type here is a single LaravelMediaLibraryData
, not an array:
Then access it normally:
How do I add thumbnails?
Add a conversions
field. Two accessor methods will be created on your model for each collection: [CollectionName][ConversionName]HTML
(which generates the full HTML tag) and [CollectionName][ConversionName]Url
(just the URL). Add them to your GraphQL type (and remember to @migrationSkip
them) to access them. Example:
Easy to fetch:
How do I get the responsive image data in a query?
Add a conversions
field with responsive: true
.
TODO: explain how to get data
How do I eager load?
Add an @eagerLoad
directive to eager load the table and avoid a N+1 problem.
Sponsors
We want to thanks to Spatie for its wonderful Spatie's Laravel Media Library.
Contributing
Any contributions are welcome. Please send a PR.
All versions of modelarium-medialibrary with dependencies
webonyx/graphql-php Version ^14.5
illuminate/support Version ^7.16
corollarium/modelarium Version ^0.4
nuwave/lighthouse Version ^5.1