Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

christophrumpel/larastreamers

238 stars
2 code files
View christophrumpel/larastreamers on GitHub

app/Rules/YouTubeRule.php

Open in GitHub
use App\Facades\Youtube;
use App\Services\Youtube\YoutubeException;
use Illuminate\Contracts\Validation\Rule;
 
class YouTubeRule implements Rule
{
public function passes($attribute, $value): bool
{
try {
$video = Youtube::video($value);
} catch (YoutubeException) {
$this->message = 'This is not a valid YouTube video id.';
 
return false;
}
 
if (is_null($video)) {
$this->message = 'This is not a valid YouTube video id.';
 
return false;
}
 
if (! $video->plannedStart->isFuture()) {
$this->message = 'We only accept streams that have not started yet.';
 
return false;
}
 
return true;
}
}

app/Http/Livewire/SubmitYouTubeLiveStream.php

Open in GitHub
use App\Rules\YouTubeRule;
use Illuminate\Validation\Rule;
use Livewire\Component;
 
class SubmitYouTubeLiveStream extends Component
{
//
protected $messages = [
'youTubeId.required' => 'The YouTube ID field cannot be empty.',
'youTubeId.unique' => 'This stream was already submitted.',
];
 
public function rules(): array
{
return [
'youTubeId' => ['required', Rule::unique('streams', 'youtube_id'), new YouTubeRule()],
'submittedByEmail' => 'required',
];
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.