webpress / media-manager
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 2 674
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 4
Open Issues: 0
Requires
- spatie/laravel-medialibrary: 7.19.5
- webpress/core: ^3.1
Requires (Dev)
- orchestra/testbench: 5.0.0
- dev-master
- 3.1.87
- 3.1.86
- 3.1.85
- 3.1.83
- 3.1.82
- 3.1.81
- 3.1.80
- 3.1.79
- 3.1.78
- 3.1.77
- 3.1.76
- 3.1.74
- 3.1.73
- 3.1.72
- 3.1.71
- 3.1.70
- 3.1.69
- 3.1.68
- 3.1.67
- 3.1.66
- 3.1.65
- 3.1.64
- 3.1.63
- 3.1.61
- 3.1.60
- 3.1.59
- 3.1.58
- 3.1.57
- 3.1.56
- 3.1.54
- 3.1.53
- 3.1.52
- 3.1.51
- 3.1.50
- 3.1.49
- 3.1.48
- 3.1.47
- 3.1.46
- 3.1.45
- 3.1.44
- 3.1.43
- 3.1.42
- 3.1.41
- 3.1.40
- 3.1.39
- 3.1.38
- 3.1.37
- 3.1.36
- 3.1.35
- 3.1.34
- 3.1.33
- 3.1.32
- 3.1.31
- 3.1.30
- 3.1.29
- 3.1.28
- 3.1.27
- 3.1.26
- 3.1.25
- 3.1.24
- 3.1.23
- 3.1.22
- 3.1.20
- 3.1.19
- 3.1.18
- 3.1.17
- 3.1.15
- 3.1.14
- 3.1.13
- 3.1.12
- 3.1.11
- 3.1.10
- 3.1.9
- 3.1.8
- 3.1.7
- 3.1.6
- 3.1.5
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.34
- 3.0.33
- 3.0.32
- 3.0.31
- 3.0.30
- 3.0.29
- 3.0.28
- 3.0.27
- 3.0.26
- 3.0.25
- 3.0.24
- 3.0.23
- 3.0.22
- 3.0.21
- 3.0.20
- 3.0.19
- 3.0.18
- 3.0.17
- 3.0.16
- 3.0.15
- 3.0.14
- 3.0.13
- 3.0.12
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.6
- 3.0.5
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.1.1
- 2.1.0
- 2.0.0
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.1
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.19.0
- 0.18.0
- 0.17.0
- 0.16.0
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-dev/v9.0
- dev-develop
This package is auto-updated.
Last update: 2022-06-17 10:31:36 UTC
README
- Media Manager for Laravel
- Installation
- Configuration
- Prepare your model
- Associating media
- Retrieve media
- S3 Disk Configuration
- APIs List
The User Component package provides a convenient way of managing application's users.
Installation
Composer
To include the package in your project, Please run following command.
composer require vicoders/media-manager
Config and Migration
Run the following commands to publish configuration and migration files.
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
php artisan vendor:publish --provider "Prettus\Repository\Providers\RepositoryServiceProvider"
php artisan vendor:publish --provider "Spatie\MediaLibrary\MediaLibraryServiceProvider"
php artisan vendor:publish --provider "VCComponent\Laravel\MediaManager\MediaManagerProvider"
Create tables.
php artisan migrate
Make a change in config/medialibrary.php
.
'media_model' => VCComponent\Laravel\MediaManager\Entities\Media::class,
Environment
In .env
file, we need some configuration.
API_PREFIX=api
API_VERSION=v1
API_NAME="Your API Name"
API_DEBUG=false
Remember to update your APP_URL
APP_URL=http://somedomain.com
Generate JWT_SECRET
in .env
file.
php artisan jwt:secret
Config
In config/filesystems
, add 'media'
in 'disk'
to create link and storage folder when you add images :
'disks' => [
...
'media' => [
'url' => env('APP_URL') . '/uploads/media',
'driver' => 'local',
'root' => public_path('uploads/media'),
],
],
In .env
, add MEDIA_DISK="media"
to use configuration of 'media'
in 'disks'
.
Now the package is ready to use.
Configuration
URL Namespace
To avoid duplication with your application's api endpoints, the package has a default namespace for its routes which is media-manager
. For example:
{{url}}/api/media-manager/collections
You can modify the package url namespace to whatever you want by modifying the MEDIA_MANAGER_NAMESPACE
variable in .env
file.
MEDIA_MANAGER_NAMESPACE="your-namespace"
Prepare your model
To associate media with a model, the model must implement the following interface and trait:
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia\HasMedia; use VCComponent\Laravel\MediaManager\HasMediaTrait; class Post extends Model implements HasMedia { use HasMediaTrait; ... }
If you want your model has media that its dimension is configable, you should include registerMediaConversions
method in your model.
public function registerMediaConversions(Media $media = null) { $media_dimension = MediaDimension::where('model', 'product')->get(); foreach ($media_dimension as $item) { $this->addMediaConversion($item->name)->width($item->width)->height($item->height)->sharpen(10); } }
Associating media
You can associate a file with a model like this:
$media_id = 2; $post = Post::create($data); $post->attachMedia($media_ids);
or you can pass an array of media ids:
$media_ids = [1, 2, 3]; $post = Post::create($data); $post->attachMedia($media_ids);
Retrieve media
There are few solution you can use to retrieve media:
Using Eloquent model relationship:
$mediaItems = $newsItem->media;
Using getMedia
method:
$mediaItems = $newsItem->getMedia();
You can retrieve media for specific collection:
$collection_name = 'image'; $mediaItems = $newsItem->getMedia($collection_name);
S3 Disk Configuration
By default all files are stored on the disk specified as the disk_name
in the config file.
If you want to use s3
to store your files, you are free to change the disk_name
configuration by just add this env variable:
MEDIA_DISK=s3
Make sure you configure the correct s3 url in config/medialibrary.php
file:
's3' => [
'domain' => 'https://'.env('AWS_BUCKET').'.s3-'.env('AWS_DEFAULT_REGION').'.amazonaws.com',
],
APIs List
Here is the list of APIs provided by the package.
Verb | URI | Action |
---|---|---|
GET | /api/{namespace}/collections |
Get list of collection with pagination |
GET | /api/{namespace}/collections/all |
Get all collections |
GET | /api/{namespace}/collections/{id} |
Get collection item |
POST | /api/{namespace}/collections |
Create collection |
PUT | /api/{namespace}/collections/{id} |
Update collection |
DELETE | /api/{namespace}/collections/{id} |
Delete collection |
------ | ------ | ------ |
GET | /api/{namespace}/media |
Get list of collection with pagination |
GET | /api/{namespace}/media/all |
Get all medias |
GET | /api/{namespace}/media/{id} |
Get collection item |
POST | /api/{namespace}/media |
Create collection |
PUT | /api/{namespace}/media/{id} |
Update collection |
DELETE | /api/{namespace}/media/{id} |
Delete collection |
PUT | /api/{namespace}/media/{id}/collection/attach |
Attach media to collection |
PUT | /api/{namespace}/media/{id}/collection/detach |
Detach media from collection |