title: How to retrieve data from Laravel cache for Laravel media library package
body: <p>When posts create, I upload a photo using Laravel media library and I can simply retrieve data from media library using:</p>
  
  <pre><code>$blog-&gt;getFirstMediaUrl('blog');
  </code></pre>
  
  <p>I use Laravel cache feature for best performance and minimum query with <code>redis</code>. I stored blog data in cache like below:</p>
  
  <pre><code>$blogs=Blog::where('publication_status', 1)
  -&gt;select('id', 'admin_id', 'category_id', 'sub_category_id', 
  'blog_section_id', 'blog_title', 'slug',
  'blog_short_description', 'blog_long_description', 'author_name',
  'thumbnail', 'publication_status', 'created_at')
  -&gt;orderBy('id', 'DESC')
  -&gt;get();
  
  Cache::forever('blogs', $blogs);
  </code></pre>
  
  <p>At that time I cached media library photo also like below:</p>
  
  <pre><code>$media=Media::all(); Cache::forever('media', $media);
  </code></pre>
  
  <p>After that I retrieved my blogs data in frontend like below: </p>
  
  <pre><code>$data['blogs']=cache()-get('blogs', function (){
      Blog::where('publication_status', 1)
      -&gt;select('id', 'admin_id', 'category_id', 'sub_category_id', 'blog_section_id', 'blog_title', 'slug',
      'blog_short_description', 'blog_long_description', 'author_name',
      'thumbnail', 'publication_status', 'created_at')
      -&gt;orderBy('id', 'DESC')
      -&gt;get();
  });
  
  return view('Frontend.includes.homepage.homepage', $data);
  </code></pre>
  
  <p>and pass $data in view file like below:</p>
  
  <pre><code>&lt;div class="single_post_content_left"&gt;
      &lt;ul class="business_catgnav  wow fadeInDown"&gt;
          @foreach($blogs
          -&gt;where('thumbnail', 1)
          -&gt;where('blog_section_id', 1)
          -&gt;take(1)
          as $main_section)
  
          &lt;li&gt;
              &lt;figure class="bsbig_fig"&gt; &lt;a href="{{ route('article', $main_section-&gt;slug) }}" class="featured_img"&gt; &lt;img alt="" src="{{
                  $main_section-&gt;getFirstMediaUrl('blog') }}"&gt; &lt;span
                  class="overlay"&gt;&lt;/span&gt; &lt;/a&gt;
  
                  &lt;figcaption&gt; &lt;a href="{{ route('article', $main_section-&gt;slug) }}"&gt;{{ $main_section-&gt;blog_title }}&lt;/a&gt;
                  &lt;/figcaption&gt;
                  &lt;p&gt;{{ $main_section-&gt;blog_short_description }}&lt;/p&gt;
              &lt;/figure&gt;
          &lt;/li&gt;
  
          &lt;small class="pull-right"&gt;&lt;i class="fa fa-clock-o"&gt;&lt;/i&gt; {{ $main_section-&gt;created_at-&gt;diffForHumans() }}&lt;/small&gt;
  
          @endforeach
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here blogs are retrieve from cache successfully without media library data: </p>
  
  <pre><code>$main_section-&gt;getFirstMediaUrl('blog');
  </code></pre>
  
  <p>But I want to retrieve my media library data from cache like blogs for minimum query run, what can I do?</p>