Download the PHP package shortcodes/media without Composer

On this page you can find all versions of the php package shortcodes/media. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package media

Deprecated

This package is deprecated. New and improved version of it here https://github.com/mindz-team/laravel-media

Mediable

Package to organise media files and it's customization

Install

composer require shortcodes/media

Usage

Model must use trait Shortcodes/Media/Mediable and implement HasMedia interface

Register collections

To register collections add method registerMediaCollections and add collections you need

public function registerMediaCollections()
{
    $this->addMediaCollection('avatar')->singleFile();
    $this->addMediaCollection('my-other-collection');
}

You can define if collection is singular (add singleFile() method) or multiple (by default)

Uploading media files

To be able to upload media files you have to set media routes. You can do that by placing Route::mediaRoutes(); in your routes file.

Then you will be able to use it under POST /media in basic namespace while providing file field

In response you will get:

If your disk is not set to public the URL you receive will be proper for chosen disk.

After uploading media it is placed in MediaLibrary and can be attach to model

Attaching single file to model

To attach file to model you need simply to make request (POST or PATCH) to create or modify model with parameters previously described in registerMediaCollections method like in example

Model::create([...$someArticleAttributes,
    'avatar': 1
]);

In avatar single collection you need to provide media id received while uploading media.

While updating model object that already have an avatar and collection is set to singleFile() avatar will be replaced

Attaching multiple files to model

To attach multiple media files to model you need simply to make request (POST or PATCH) to create or modify model with parameters previously described in registerMediaCollections method like in example

Model::create([...$someArticleAttributes,
    'my-other-collection': [1,2,3,4]
]);

In my-other-collection property collection you need to provide array of media ids received while uploading media.

REMEMBER! While updating model object collection not set to single all skipped media id in array will be deleted.

In this case images are automatically reordered by provided ids.

Attaching multiple files to model without removing actual

In case you need to add media file without removing all missing in array you can use add key in collection data request

Model::create([...$someArticleAttributes,
    'my-other-collection': [
        'add' => [1]
    ]
]);

Deleting selected files from model

In case you need to remove selected media from object you can use delete key in collection data request

Model::create([...$someArticleAttributes,
    'my-other-collection': [
        'delete' => [3, 4]
    ]
]);

Attaching file while uploading

You may also attach file directly to demanded models providing proper fields in request model_type,model_id,model_collection.

The model_collection field is optional. Remember that model_type must use trait Mediable

Attach manipulations to uploaded image

You may also add some manipulations to uploaded media.

For now only available manipulation ther is is cropping.

You can perform it by performing PATCH request

PATCH /media/{mediaId}

{
   "manipulations": [
       {
           "type":"crop",
           "x":0, 
           "y":0,
           "width":10,
           "height": 500
       }
   ]
}

where x and y are coordinates to starting point and width and height are dimentions of cropped rectangle.

Additional features

More about library can be found at official documentation page https://github.com/spatie/laravel-medialibrary


All versions of media with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.0
spatie/laravel-medialibrary Version ^9.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package shortcodes/media contains the following files

Loading the files please wait ....