Hello Alex, you upload your videos to vimeo and cannot access these videos from the browser directly. For example we cannot access https://player.vimeo.com/video/1010746273?title=0&byline=0&autoplay=1&dnt=1&app_id=122963 directly. But when we are a member of your system, we can view the videos. Can you tell me how you did that? Thank you in advance.
Sure thing! Here's a rough idea of how it works:
Videos are uploaded through Vimeo API with their visibility set to private embeddable, so they can be embedded but not accessed directly.
Videos are also set to only be allowed to play on the codecourse.com
domain
I store the vimeo_id
and vimeo_hash
in the episodes
table of the database (obtained from the API when a new video is pushed through admin)
Each episode has an API resource that looks like this:
class EpisodeResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
// Other things up here
'vimeo_id' => ($this->free || $this->course->free || auth()->user()?->hasSubscription()) ? $this->vimeo_id : null,
'vimeo_hash' => $this->vimeo_hash,
];
}
}
This hides the vimeo_id
in the response so unless you have a membership or the episode is free, you can't see it.
vimeo_id
and vimeo_hash
. I won't post the code for this, but any way you now embed — you've protected against the vimeo_id
being visible and it'll only play on the codecourse.com
domain.Hope this helps, and let me know if you have any questions!