-
app/Rules/YouTubeRule.php
Open in GitHubuse 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 GitHubuse 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', ]; } // }