My Blog Posts

Laravel Media Uploader Package

Laravel Media Uploader Package

Laravel Media Uploader installs files using the Spatie media library package before saving it to the model. You can then add the uploaded file to the model with a controller:

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

According to the Readme file, media processing occurs in the following ways:

  • All videos will be converted to mp4 format.
  • All audio files will be converted to mp3.
  • The width and height and ratio of all images are recorded privately.
  • The duration of all videos and sounds is recorded as a special feature.

You can also add media more specifically:

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

In Frontend, this package is created with a complementary Vue component ( laravel-file-installer).

For details about the Frontend component, see component usage documentation; An example looks like this:

:tokens="{{ json_encode(old('media', [])) }}"
label="Upload Avatar"
notes="Supported types: jpeg, png, jpg, gif"

The package also contains some REST API endpoints to access uploaded files, view recently installed files, and show deleted media files.

You can get more information about this package and all installation instructions and view the source code on GitHub at ahmed-aliraqi/laravel-media-uploader.

Share this article

Comments (0)