此包以前使用 laravel-media-library 上传文件,然后再保存模型。
This package used to upload files using laravel-media-library before saving model.
In this package all uploaded media will be processed.
mp4.mp3.width & height & ratio will be saved as custom property. duration will be saved as custom property.composer require ahmed-aliraqi/laravel-media-uploaderThe package will automatically register a service provider.
You need to publish and run the migration:
php artisan vendor:publish --provider="AhmedAliraqi\LaravelMediaUploader\Providers\UploaderServiceProvider" --tag="migrations"
php artisan migratePublish laravel-media-library migrations:
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="migrations"
php artisan migrateIf you want to customize
attachmentsvalidation rules, you should publish the config file:
php artisan vendor:publish --provider="AhmedAliraqi\LaravelMediaUploader\Providers\UploaderServiceProvider" --tag="config"If you want to customize validation translations, you should publish the
langfiles:
php artisan vendor:publish --provider="AhmedAliraqi\LaravelMediaUploader\Providers\UploaderServiceProvider" --tag="uploader:translations"This is the default content of the config file:
…Use
HasUploadertrait in your model:
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 inrequest('media')with any collection.If you want to save specific collection name add it to the second argument.
// specified collection name
$blog->addAllMediaFromTokens([], 'pictures');
// specified tokens
$blog->addAllMediaFromTokens($request->input('tokens', []), 'pictures');npm i laravel-file-uploader --save-devNow you should register the component in your
resources/js/app.js:
// app.js
import FileUploader from 'laravel-file-uploader';
Vue.use(FileUploader);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"
>| 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 |
暂无开放 Issues,或尚未同步最近议题。