The Laravel Media Uploader package by Ahmed Fathy uploads files using Spatie’s media library package before saving a model. You can then attach uploaded media to the model in a controller:
1class BlogController extends Controller 2{ 3 public function store(Request $request) 4 { 5 $blog = Blog::create($request->all()); 6 7 $blog->addAllMediaFromTokens(); 8 9 return back();10 }11}
According to the readme, media processing happens in the following ways:
- All videos will be converted to mp4.
- All audios will be converted to mp3.
- All images width & height & ratio will be saved as custom property.
- All videos & audios duration will be saved as a custom property.
You can also attach media more specifically:
1// specified collection name2$blog->addAllMediaFromTokens([], 'pictures');3 4// specified tokens5$blog->addAllMediaFromTokens($request->input('tokens', []), 'pictures');
On the frontend, this package is stitched together with a companion Vue component (laravel-file-uploader):
Check out the component usage doc for details on the frontend component; a basic example might look like the following:
1<file-uploader2 :max="1"3 collection="avatars"4 :tokens="{{ json_encode(old('media', [])) }}"5 label="Upload Avatar"6 notes="Supported types: jpeg, png, jpg, gif"7 accept="image/jpeg,image/png,image/jpg,image/gif"8></file-uploader>
The package also includes some REST API endpoints to access uploaded files, display recently uploaded files, and show deleted media files.
You can learn more about this package, get full installation instructions, and view the source code on GitHub at ahmed-aliraqi/laravel-media-uploader.
0 comments:
Post a Comment
Thanks