Download the PHP package actengage/media without Composer
On this page you can find all versions of the php package actengage/media. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package media
Media
This package provides a unit tested API to manage different types of files which can be related to Eloquent models (many to many relationships). Each type of file can be associated to its own resource for additional processing and manipulation. For instance, images are processed with the Image
resource and manipulated with Intervention Image. API's are provides for creating your own resources.
Features
Media
Eloquent Model and Migrations.Mediable
trait to relate any eloquent model to theMedia
model.Resource
API to add support for additional types of media.Plugin
API which adds optional features, like color extraction for images.- Uses File Storage to manage files.
- Uses Intervention Image to manage and manipulate images.
- Unit tested
Requirements
- Laravel 9.x+
- PHP 8.x+
- Intervention Image 2.x+
- GD or Imagick
Getting Started
Install via Composer
Publish the config file
Optional, publish the migration files
Resource Factory
The resource factory provides a unified interface for creating a variety of resources. You can even create your own resource classes and register them in config/media.php
. By default, there are two types of resources: Image
and File
. For instance, you could define an Audio
or Video
resource. Resources are processed in the order they are defined.
Resource Methods
Every resource share a set of standard methods. And each type of resource may define its own method. Methods are chainable.
Conditional Resource Methods
Sometimes you may not know what kind of resource you are creating. You can use the is()
method to conditionally chain methods to a specific resource types. Use the key configuration in config/media.php
for matching or fully qualified class name.
You may also need to check for true
and false
values before executing code on a resource. For these scenarios, you may use when()
and not()
methods to conditionally chain methods to the resource.
php use Actengage\Media\Facades\Resource;
$resource = Resource::request('image');
// Context allows you to give a simple string to assign from context to // resources. For example, if you want to notate a resource is an image. $resource->context('image');
// Meta data is a key/value store that is saved as JSON in the database. // Similar to context, but this allows you to associate custom meta data // with a resource instance. $resource->meta([ 'some_key' => 'Some value goes here.' ]);
// Meta can be also added using individual arguments. $resource->meta('another_key', 'Another key goes here.');
// Tags add an array of keys as context to a resource. $resource->tags(['a', 'b', 'c']);
// Tags can be added using individual arguments or an array. $resource->tags('d', 'e', 'f');
## Events
Similar to Eloquent events, `Resource` event handlers work the same way. There are two ways to bind events, globally to a `Resource` class, or on the instance of a resource. The difference is global event binding is handled for all resources, whereas the instance methods are only fired for that instance.
### Global Methods
### Instance Methods
## Query Scopes
The `Media` model provides some convenient scopes for searching.
## Mediable Trait
The `Mediable` trait is used to associate `Media` models to your custom models. `Media` models are related using `morphToMany` relationships.
*Document.php*
*Basic Usage*
## Plugins
Plugins are used to add additional functionality to resources not provided by the core API's. This is an example of the `ExtractImageColors` plugin that extracts the common colors from an image and stores them in the model. A plugin has instance methods which apply to the specific resource that is being manipulated. Or as event handlers.
A `Plugin` class can be used in one of two ways. The first way is to bind it statically to the resource it should be used with. The second way is by defining it in the `config/media.php` file. In the config, plugins can be bound to specific resources or globally for all resources.
*Static Binding*
*config/media.php*
*Plugins/ExtractImageColors.php*
All versions of media with dependencies
laravel/framework Version ^11.0
intervention/image Version ^2.7
ksubileau/color-thief-php Version ^2.0
psr/http-message Version ^1.0
guzzlehttp/guzzle Version ^7.4