https://github.com/runthis/laravel-media
Tiny package to conveniently handle single file media uploads in Laravel.
https://github.com/runthis/laravel-media
laravel laravel9 media
Last synced: 10 months ago
JSON representation
Tiny package to conveniently handle single file media uploads in Laravel.
- Host: GitHub
- URL: https://github.com/runthis/laravel-media
- Owner: runthis
- License: mit
- Created: 2022-06-28T22:37:39.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-02-09T13:27:21.000Z (over 1 year ago)
- Last Synced: 2025-02-09T14:29:46.091Z (over 1 year ago)
- Topics: laravel, laravel9, media
- Language: PHP
- Homepage:
- Size: 76.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Media
A tiny laravel package to conveniently handle single file media uploads with little configuration.
## Installation
composer require runthis/laravel-media
## Usage
Add to the file you want to process uploads in, such as a controller.
use Runthis\Media\Facades\Media;
use Runthis\Media\Requests\MediaRequest;
Include the `MediaRequest` class in the function parameter and execute the `create` method on the `Media` facade.
Example:
public function upload(MediaRequest $request) {
$test = Media::create($request);
dd($test);
}
Inside the `dd()` you can see the complete object details and process these as you see fit (such as keeping track of these uploads in a database if you like).
Within the object results is a `size` key. You can simply echo this out to get the bytes, or you can add `->pretty()` to get a prettier output.
You can also pass a string parameter to the `pretty()` method.
Options:
l: lowercase suffix (12.45 mb instead of 12.45 MB)
s: spacing omitted (12.45MB instead of 12.45 MB)
b: Ending "B" removed (12.45 M instead of 12.45 MB)
Examples:
$test->size->pretty('sb'); // 12.45M
$test->size->pretty('ls'); // 12.45m
$test->size->pretty('l'); // 12.45 mb
$test->size->pretty('bl'); // 12.45 m
*The `Media::create` method expects a file with the key named file.*
## Publish Config
If you want, run the below command to add a media.php file to your config folder.
php artisan vendor:publish --tag="media-config"
From the media config file you can change the storage disk name and the rules for the media (such as file types, size limit, etc).
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.