-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValidYoutubeVideo Rule #145
ValidYoutubeVideo Rule #145
Conversation
src/Rules/ValidYoutubeVideo.php
Outdated
{ | ||
try { | ||
$videoId = Youtube::parseVidFromURL($value); | ||
$video = Youtube::getVideoInfo($videoId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should define the $part argument as ['id'] (cost 0 quota) as you only need to check, not fetch the actual video data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, will change this
.gitignore
Outdated
@@ -1,5 +1,32 @@ | |||
# General |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this file is included in the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me neither, will remove this
src/Rules/ValidYoutubeVideo.php
Outdated
@@ -28,7 +28,7 @@ public function passes($attribute, $value) | |||
{ | |||
try { | |||
$videoId = Youtube::parseVidFromURL($value); | |||
$video = Youtube::getVideoInfo($videoId); | |||
$video = Youtube::getVideoInfo($videoId)['id']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the idea was to only request the id not to assign only the id
=> Youtube::getVideoInfo($videoId, ['id']);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorted this issue, thank you.
.gitignore
Outdated
@@ -1,5 +0,0 @@ | |||
/vendor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you totally removed the .gitignore in the repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Korko thank you, how do you remove the single file from the pull request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how using the github interface but in git, should be simple:
git fetch
git checkout origin/master -- .gitignore
should reset the file to the master version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how using the github interface but in git, should be simple:
git fetch
git checkout origin/master -- .gitignore
should reset the file to the master version
Thank you, this worked and I've pushed to PR
Indeed. But careful, you've added also two binary files in the last commit: src/._YoutubeServiceProvider.php and src/Rules/._ValidYoutubeVideo.php not sure it was wanted. |
This reverts commit ff7eced.
This is not going well haha! Thank you, I think I've sorted it now 🤞 |
@alasdairgallacher This looks good to me, please just add this to the readme doc, otherwise nobody will know that it exists ; ) @Korko Thank you for the followup |
@alaouy Thank you! I've added to the readme doc under usage section. Please let me know if anything needs changing 👍 |
Love this package and wanted to make a PR to contribute this.
Here's a feature which makes life so much easier for validating YouTube videos urls.
Example of usage:
'youtube_video_url' => ['bail', 'required', new ValidYoutubeVideo]
To prevent unnecessary queries, you can use the
bail
rule.If the validation rule fails the default error message will be:
@alaouy I'm more than happy to spend some time creating the other validation rules for (channel, etc).