Blame view

app/Traits/Media.php 841 Bytes
b7c7a5f6   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  <?php
  
  namespace App\Traits;
  
  use Plank\Mediable\Mediable;
  
  /**
   * Mediable Trait.
   *
   * Provides functionality for attaching media to an eloquent model.
   *
   * @author Sean Fraser <sean@plankdesign.com>
   *
   * Whether the model should automatically reload its media relationship after modification.
   */
  trait Media
  {
      use Mediable;
  
      /**
       * Relationship for all attached media.
       * @return \Illuminate\Database\Eloquent\Relations\MorphToMany
       */
      public function media()
      {
          $media = $this->morphToMany(config('mediable.model'), 'mediable')
              ->withPivot('tag', 'order')
              ->orderBy('order');
  
          // Skip deleted media if not detached
          if (config('mediable.detach_on_soft_delete') == false) {
              $media->whereNull('deleted_at');
          }
  
          return $media;
      }
  }