Laravel Media Pack

An easy solution to add files to your better models with the image manipulation you are in!

This package allows you to MediaUploaderclass. By default, the MediaUploader class uses the disk specified in the media configuration provided by the package. Saves the file as a cleaned version and creates a media record in the database.

Here are some examples of the basic and customized use of the MediaUploader class:

$file = $request->file('file');// Default usage$media = MediaUploader::fromFile($file)->upload();// Custom usage$media = MediaUploader::fromFile($file) ->useFileName('custom-file-name.jpeg') ->useName('Custom media name') ->upload();

Here's an example of associating media with a model:

use Optix\Media\HasMedia;class Post extends Model{ use HasMedia;}$post = Post::first();// To the default group$post->attachMedia($media);// To a custom group$post->attachMedia($media, 'custom-group');

You can also save media conversions to a service provider and then perform them in a model:

// In a service provider's boot() method...Conversion::register('thumb', function (Image $image) { return $image->fit(64, 64);});// Perform a conversion on a modelclass Post extends Model{ use HasMedia; public function registerMediaGroups() { $this->addMediaGroup('gallery') ->performConversions('thumb'); }}

You can learn more about this package, get all the installation instructions and find the source code on GitHub at optixsolutions / laravel-media .


KARABAY A, 2019 . Laravel Media Pack,

(Accessed July 17, 2019).

  Share this post

Comments (0)


Sign up for the email newsletter to be the first to know about my blog posts