Download the PHP package anisaronno/laravel-media-gallery without Composer
On this page you can find all versions of the php package anisaronno/laravel-media-gallery. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download anisaronno/laravel-media-gallery
More information about anisaronno/laravel-media-gallery
Files in anisaronno/laravel-media-gallery
Package laravel-media-gallery
Short Description Laravel Settings Table
License MIT
Homepage https://github.com/anisAronno/laravel-media-media
Informations about the package laravel-media-gallery
Laravel Media Gallery
Table of Contents
- Laravel Media Gallery
- Table of Contents
- Introduction
- Installation
- Publish Migration and Config
- Publish Migration, Config
- Uses
- Eloquent Factories Relation Mapping
- Retrieve media by owner
- Authentication and Configuration
- Customizing Authentication Guard:
- Restricting Media Viewing:
- Defining Gate for Managing Media:
- Cache Expiry Time:
- Use Media with Relational Model
- Working with Single or Featured Media
- Helper Methods
- API Route for Media/Media
- Fetch Media/Media from Relational Model
- Contribution Guide
- License
Introduction
The Laravel Media Gallery simplifies media and media file management in your Laravel project. This README provides installation instructions, usage examples, and additional information.
Installation
To get started, install the package using Composer:
Publish Migration and Config
For media library features, follow these steps:
Publish Migration, Config
Publish the migration, factory and seeder file:
Publish the Config file:
Run Migration
Apply the migrations to set up the media storage table:
Uses
To use media storage in any model (e.g., User Blog, Product), add the HasMedia
trait:
Eloquent Factories Relation Mapping
For setting up seed data with relation mapping (e.g., User has Blog, Blog uses HasMedia Trait), use the following code in a seeder:
Retrieve media by owner
To retrieve media by the user, use the HasMedia
trait on the User/Team/Admin or any other model authorized to upload media:
Absolutely, here's the updated text with subheadings for each section:
Authentication and Configuration
Customizing Authentication Guard:
You can customize the authentication guard for the routes by publishing the config file and changing the 'guard' key to your desired authentication guard.
Alternatively, you can use the API middleware.
Restricting Media Viewing:
Set view_all_media_anyone
to false
to restrict media viewing to user-uploaded images only; default is true
, allowing all media viewing.
Defining Gate for Managing Media:
Defines canManageMediaContent
gate in AuthServiceProvider.php
allowing designated users to manage media content.
Cache Expiry Time:
Set Cache Expiry time. Default value is 1440.
Use Media with Relational Model
For storing media for a relational model (e.g., Blog), use the following methods:
- Attach:
$blog->media()->attach(array $id)
- Sync:
$blog->media()->sync(array $id)
- Delete:
$blog->media()->detach(array $id)
Working with Single or Featured Media
To work with a single or featured media, use the featuredMedia
method and set isFeatured
to true
in the second parameter:
- Attach:
$blog->featuredMedia()->attach(array $id, ['is_featured' => 1])
Note: Sync and detach are the same; use featuredMedia
instead of featuredMedia
.
Helper Methods
You can also use helper methods for media management:
-
For Attach:
$blog->attachMedia(array $ids, $isFeatured = false)
- For Sync:
$blog->syncMedia(array $ids, $isFeatured = false)
- For Delete:
$blog->detachMedia(array $ids, $isFeatured = false)
API Route for Media/Media
To manage your media storage, you can use the following routes:
- Get all media:
api/media
(GET) - Get a single media:
api/media/{id}
(GET) - Store an media:
api/media
(POST) - Delete an media:
api/media/{id}
(DELETE) - Update an media:
api/media/update/{id}
(POST) - Batch Delete:
media/batch-delete
(POST)
Fetch Media/Media from Relational Model
To retrieve media/media from a relational model:
-
Fetch all media as an array:
$blog->media
- Fetch the featured media only:
$blog->media
You can access media properties like URL, title, mimes, size, and type:
$media->url
$media->title
$media->mimes
$media->size
$media->type
Contribution Guide
Please follow our Contribution Guide if you'd like to contribute to this package.
License
This package is open-source software licensed under the MIT License.
All versions of laravel-media-gallery with dependencies
laravel/framework Version ^8.0|^9.0|^10.0|^11.0
anisaronno/laravel-media-helper Version *