Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sertxudeveloper/laravel-media-model
Attach media files to your Eloquent models
https://github.com/sertxudeveloper/laravel-media-model
attachments eloquent hacktoberfest laravel laravel-model laravel-package media sertxudeveloper
Last synced: about 1 month ago
JSON representation
Attach media files to your Eloquent models
- Host: GitHub
- URL: https://github.com/sertxudeveloper/laravel-media-model
- Owner: sertxudeveloper
- License: mit
- Created: 2022-06-01T16:41:22.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-07T09:21:32.000Z (3 months ago)
- Last Synced: 2024-11-10T03:59:29.304Z (about 1 month ago)
- Topics: attachments, eloquent, hacktoberfest, laravel, laravel-model, laravel-package, media, sertxudeveloper
- Language: PHP
- Homepage:
- Size: 521 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Attach media files to your models
![](https://img.shields.io/github/v/release/sertxudeveloper/laravel-media-model) ![](https://github.com/sertxudeveloper/laravel-media-model/actions/workflows/run-tests.yml/badge.svg) ![](https://img.shields.io/github/license/sertxudeveloper/laravel-media-model) ![](https://img.shields.io/github/repo-size/sertxudeveloper/laravel-media-model) ![](https://img.shields.io/packagist/dt/sertxudeveloper/laravel-media-model) ![](https://img.shields.io/github/issues/sertxudeveloper/laravel-media-model) ![](https://img.shields.io/packagist/php-v/sertxudeveloper/laravel-media-model) [![Codecov Test coverage](https://img.shields.io/codecov/c/github/sertxudeveloper/laravel-media-model)](https://app.codecov.io/gh/sertxudeveloper/laravel-media-model)
When developing an app, you may want to attach media files to your models, such as images, videos, or documents.
With this package, you can easily attach media files to your models.The media files are stored in the specified disk and are related to the model using your database.
You can link local media files or remote ones without needing to download them to your server.
The main difference between this package and the other ones available is that this package allows you to relate media files to your models using a custom table per model.
Allowing you to manage the media tables per model instead of one unique media table for all models.
## Installation
You can install the package via composer:
```bash
composer require sertxudeveloper/laravel-media-model
```Next, you should publish the config file and the migrations:
```bash
php artisan vendor:publish --provider "SertxuDeveloper\Media\MediaServiceProvider"
```After that, you can run the new migrations:
```bash
php artisan migrate
```Finally, you can start using the package!
## Usage
You should modify the model that you want to attach media files to.
```php
**Note**
> If you don't specify a disk, the default disk will be used.```php
addMediaFromDisk(path: '/images/image.jpg', disk: 'public');
```You can also attach a remote file:
> **Note**
> This will not download the file to your server. It will only add the remote file path to the database.```php
addMediaFromUrl('https://www.sertxudeveloper.com/assets/logo.svg');
```Also, you can attach a file content, this will save the file to the disk and attach it to the model.
> **Note**
> This is useful if you get the content of a file from an external source, like as an email attachment read by a mail parser.```php
addMediaFromContent(
content: file_get_contents('/tmp/tmpA3ds2'),
originalName: 'image.jpg',
toFolder: 'avatars',
toDisk: 'public'
);
```## Testing
This package contains tests, you can run them using the following command:
```bash
composer test
```## Contributing
Please see [CONTRIBUTING](https://github.com/sertxudeveloper/.github/blob/main/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Sergio Peris](https://github.com/sertxudev)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
Copyright © 2022 Sertxu Developer