---
title: "Reading media — Media Library for Laravel | Roundly"
description: "Read an owner's media through MediaLibrary::for() — collections, first media, URLs and temporary URLs — plus attributes."
url: https://roundly-consulting.com/open-source/docs/media-library-for-laravel/reading-media
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Media Library for Laravel](https://roundly-consulting.com/open-source/docs/media-library-for-laravel.md)

# Reading media

The for($model) handle reads, clears and deletes one owner's media. It never returns another owner's rows:

```php
$media = MediaLibrary::for($user);

$media->get('avatar');                           // Collection<Media>, ordered
$media->first('avatar');                         // ?Media
$media->has('avatar');                           // bool
$media->find($uuid);                             // ?Media — only if this user owns it
$media->url('avatar');                           // first URL, the bucket fallback, or ''
$media->url('avatar', 'thumb');                  // a variant's URL
$media->temporaryUrl('avatar', expiry: now()->addMinutes(10));
$media->clear('avatar');                         // delete every media in the bucket; returns the count
$media->delete($photo);                          // throws MediaDoesNotBelongToModel for someone else's media
```

## The trait shorthand

The trait mirrors the readers on the model:

```php
$user->getMedia('avatar');                  // Collection<Media>, ordered
$user->getFirstMedia('avatar');             // ?Media
$user->getFirstMediaUrl('avatar', 'thumb'); // a variant's URL, the fallback, or ''
$user->getFirstTemporaryUrl('avatar');      // time-limited URL for private media
$user->hasMedia('avatar');                  // bool
$user->clearMediaBucket('avatar');          // delete every media in the bucket
```

## Media attributes

Each Media exposes the usual file metadata plus arbitrary custom properties:

```php
$media->name;                  // display name
$media->file_name;             // stored filename
$media->mime_type;             // 'image/webp'
$media->size;                  // bytes
$media->custom_properties;     // array
$media->getCustomProperty('alt');
$media->uuid;                  // stable public id
```

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/media-library-for-laravel.md)
