Download the PHP package marqant-lab/laravel-medialibrary-graphql without Composer
On this page you can find all versions of the php package marqant-lab/laravel-medialibrary-graphql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marqant-lab/laravel-medialibrary-graphql
More information about marqant-lab/laravel-medialibrary-graphql
Files in marqant-lab/laravel-medialibrary-graphql
Package laravel-medialibrary-graphql
Short Description Package for assign and get media files with Eloquent models through GraphQL.
License MIT
Informations about the package laravel-medialibrary-graphql
Laravel Medialibrary GraphQL
This package contains GraphQL queries and mutations to manage any type of media files and make them attacheable to any given model.
About
We use Lighthouse for GraphQL.
The management of the mediafiles is based on the spatie/laravel-medialibrary package.
By default this package uses Model from config auth.providers.users.model
for assign files.
But you can change this after publish package config and change
'laravel-medialibrary-graphql.models.default'
value.
Installation
Require the package through composer.
You will have to run the migrations to setup the media table.
Publish the configuration.
In this config you can specify a model to assign files to ('models.default')
and many other settings. The model should implements Spatie\MediaLibrary\HasMedia
interface and use Spatie\MediaLibrary\InteractsWithMedia
trait.
For example User model:
Also you can add as many models as you need.
Example of config:
But in this case you need to send 'model' param for getMedia() query and uploadFile()
and deleteAllMedia() mutations.
If 'model' param is empty (null) then 'models.default' model will be taken to attach files.
If you need Spatie\MediaLibrary config:
If you plan to use the web route 'media/download/' to download files, add the
MEDIA_API_KEY
variable to your .env
file to secure your application's
downloads with an api key.
You need to set this key as 'apiKey' at headers.
This package uses it's own @guardMedia
directive for secure.
By default 'guard' in config is 'sanctum' but you can change
it after publish package's config file.
You can setup our
marqant-lab/auth-graphql
package for auth and follow all instructions of the package.
After this add import to your schema.graphql
Queries
Query | Requires input | Returns |
---|---|---|
getMedia | id: Int! (ID of the model need to delete all files from), | [Media] |
model: String (model key from config, if null 'default' | ||
model will be taken) | ||
downloadMedia | uuid: String! | String! |
Mutations
Mutation | Requires input | Returns |
---|---|---|
uploadFile | id: Int! (ID of the model need to attach file to), | [Media] |
file: Upload!, | ||
model: String (model key from config, | ||
if null 'default' model will be taken), | ||
name: String, properties: Json | ||
deleteMedia | uuid: String! | String |
deleteAllMedia | id: Int! (ID of the model need to delete all files from), | String |
model: String (model key from config, | ||
if null 'default' model will be taken), |
uploadFile mutation example:
plus 'file' type Upload (models)
response example:
Tests
If you want to execute package tests add this to the phpunit.xml
And after you can check it by executing:
All versions of laravel-medialibrary-graphql with dependencies
nuwave/lighthouse Version ^4.16
spatie/laravel-medialibrary Version ^8.0.0
marqant-lab/lighthouse-json Version ^0.0.2
marqant-lab/auth-graphql Version ^0.0.11