Last active
November 11, 2022 05:26
-
-
Save DarkGhostHunter/e8e75e52153a122195ccfb0ca9904fae to your computer and use it in GitHub Desktop.
A controller using the CachesResponse trait
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controllers; | |
use App\Podcast; | |
use App\Http\Helpers\CachesResponses; | |
use Illuminate\Http\Request; | |
use Podcast\PodcastAnalytics\PodcastAnalytics; | |
class PodcastController extends Controller | |
{ | |
use CachesResponses; | |
/** | |
* Show the analytics for the Podcast | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \App\Podcast $podcast | |
* @param \Podcast\PodcastAnalytics\PodcastAnalytics $analytics | |
* @return \Illuminate\Http\Response | |
*/ | |
public function showAnalytics(Request $request, Podcast $podcast, PodcastAnalytics $analytics) | |
{ | |
if ($podcast->disabled) { | |
return view('podcast.show.disabled', ['podcast' => $podcast]); | |
} | |
if (! $podcast->has_analytics) { | |
return view('podcast.show.analytics.wait', ['podcast' => $podcast]); | |
} | |
return view('podcast.show.analytics', [ | |
'podcast' => $podcast, | |
'analytics' => $this->remember($request, fn() => $analytics->for($podcast)->gather()) | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment