Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

laravel-media-uploader

> 编程语言
Open source

This package used to upload files using laravel-media-library before saving model.

340 stars0 likes1 views
WebsiteGitHub

About

This package used to upload files using laravel-media-library before saving model.

Laravel Media Uploader

This package used to upload files using laravel-media-library before saving model.

In this package all uploaded media will be processed.

  • All videos will converted to mp4.
  • All audios will converted to mp3.
  • All images width & height & ratio will be saved as custom property.
  • All videos & audios duration will be saved as custom property.

Requirements

  • PHP >= 7.4
  • You should be ensured that the ffmpeg was installed on your server

Installation

bash
composer require ahmed-aliraqi/laravel-media-uploader

The package will automatically register a service provider.

You need to publish and run the migration:

bash
php artisan vendor:publish --provider="AhmedAliraqi\LaravelMediaUploader\Providers\UploaderServiceProvider" --tag="migrations"

php artisan migrate

Publish laravel-media-library migrations:

bash
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="migrations"
php artisan migrate

If you want to customize attachments validation rules, you should publish the config file:

bash
php artisan vendor:publish --provider="AhmedAliraqi\LaravelMediaUploader\Providers\UploaderServiceProvider" --tag="config"

If you want to customize validation translations, you should publish the lang files:

bash
php artisan vendor:publish --provider="AhmedAliraqi\LaravelMediaUploader\Providers\UploaderServiceProvider" --tag="uploader:translations"

This is the default content of the config file:

…

Use HasUploader trait in your model:

php
 In your controller use `addAllMediaFromTokens()` method to assign the uploaded media to model using the generated tokens:

```php
class BlogController extends Controller
{
        public function store(Request $request)
        {
            $blog = Blog::create($request->all());
            
            $blog->addAllMediaFromTokens();
    
            return back();
        }
}

If you do not add any arguments in addAllMediaFromTokens() method will add all tokens in request('media') with any collection.

If you want to save specific collection name add it to the second argument.

php
// specified collection name
$blog->addAllMediaFromTokens([], 'pictures');

// specified tokens
$blog->addAllMediaFromTokens($request->input('tokens', []), 'pictures');

Front End Basic Usage

blade
Or Install Component Via NPM
bash
npm i laravel-file-uploader --save-dev

Now you should register the component in your resources/js/app.js:

javascript
// app.js

import FileUploader from 'laravel-file-uploader';

Vue.use(FileUploader);

Usage

blade
getMediaResource('avatars') }}"
               :unlimited="true"
               collection="avatars"
               :tokens="{{ json_encode(old('media', [])) }}"
               label="Upload Avatar"
               notes="Supported types: jpeg, png,jpg,gif"
               accept="image/jpeg,image/png,image/jpg,image/gif"
>
Attributes
Attribute Rule Type Description
media optional - default: [] array used to display an existing files
unlimited optional - default:false boolean upload unlimited files - if let it false will not be multiple select
max optional - default:12 int the maximum uploaded files - if 1 will not me multiple select
accept optional - default: * string the accepted mime types
form optional - default: false string the form id of the uploaded media
notes optional - default null string the help-block that will be displayed under the files
label optional - default null string the label of the uploader
collection optional - default default string the media library collection that the file will store in
tokens optional - default: [] array the recently uploaded files tokens, used to display recently uploaded files in validation case
max-width optional - default: 1200 string The maximum width of uploaded image
max-height optional - default: 1200 string The maximum height of uploaded image

API

  • Upload Files
    • endpoint: /api/uploader/media/upload
    • method: POST
    • body:
      • files[]: multipart form data
    • response:
  • Display Recently Uploaded Files
    • endpoint: /api/uploader/media
    • method: GET
    • params:
      • tokens[]: temporary token
    • response:
  • Delete Files
    • endpoint: /api/uploader/media/{id}
    • method: DELETE
    • response:

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言