Download the PHP package turahe/media without Composer
On this page you can find all versions of the php package turahe/media. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package media
Laravel Media
An easy solution to attach files to your Eloquent models, with image manipulation built in!
Table of Contents
- Installation
- Key Concepts
- Uploading Media
- From Uploaded File
- From URL
- From Base64 String
- Customizing Uploads
- Associating Media with Models
- Disassociating & Deleting Media
- Retrieving Media
- Image Manipulation & Conversions
Installation
Install the package via Composer:
Publish the assets to create the necessary migration and config files:
Key Concepts
- Media can be any file type (image, document, etc). Restrict file types in your own validation logic.
- Media is uploaded as its own entity and can be managed independently.
- Associations: Media must be attached to a model to be related.
- Groups: Media items are bound to "groups" (e.g., images, documents) for flexible associations.
- Conversions: You can define image conversions (e.g., thumbnails) to be performed when media is attached.
- Global Conversions: Conversions are registered globally and reusable across models.
Uploading Media
Use the Turahe\Media\MediaUploader
class to handle file uploads. By default, files are saved to the disk specified in your media config, with a sanitized file name, and a media record is created in the database.
From Uploaded File
Customizing Uploads
You can customize the file name and media name before uploading:
From URL
Upload media directly from a remote URL:
From Base64 String
Upload media from a base64-encoded string (with or without a data URI prefix):
Associating Media with Models
To associate media with a model, include the Turahe\Media\HasMedia
trait:
Attach media to a model:
Disassociating & Deleting Media
Detach media from a model:
Delete a media item (removes file and associations):
Retrieving Media
Retrieve media attached to a model:
Get URLs for media:
Image Manipulation & Conversions
You can define image conversions (e.g., thumbnails) using the familiar intervention/image
library. Register conversions in a service provider:
Configure a media group to perform conversions:
Get the URL of a converted image:
All versions of media with dependencies
guzzlehttp/guzzle Version ^7.9
kalnoy/nestedset Version ^6.0
spatie/eloquent-sortable Version ^4.4