Associating files

You can associate a file with a model like this:

$newsItem = NewsItem::find(1);
$newsItem
   ->addMedia($pathToFile)
   ->toMediaLibrary();

The file will now be associated with the NewsItem instance and will be moved to the disk you've configured.

If you want to not move, but copy, the original file you can call preservingOriginal:

$newsItem
   ->addMedia($pathToFile)
   ->preservingOriginal()
   ->toMediaLibrary();

You can also add a remote file to the media library:

$url = 'http://medialibrary.spatie.be/assets/images/mountain.jpg';
$newsItem
   ->addMediaFromUrl($url)
   ->toMediaLibrary();