Skip to content
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

Merged
merged 10 commits into from
May 22, 2020

Conversation

alasdairgallacher
Copy link
Contributor

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:

The supplied URL does not look like a Youtube URL.

@alaouy I'm more than happy to spend some time creating the other validation rules for (channel, etc).

{
try {
$videoId = Youtube::parseVidFromURL($value);
$video = Youtube::getVideoInfo($videoId);
Copy link

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.

Copy link
Contributor Author

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
Copy link

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.

Copy link
Contributor Author

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

@@ -28,7 +28,7 @@ public function passes($attribute, $value)
{
try {
$videoId = Youtube::parseVidFromURL($value);
$video = Youtube::getVideoInfo($videoId);
$video = Youtube::getVideoInfo($videoId)['id'];
Copy link

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']);

Copy link
Contributor Author

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
Copy link

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.

Copy link
Contributor Author

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?

Copy link

@Korko Korko May 3, 2020

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

Copy link
Contributor Author

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

@Korko
Copy link

Korko commented May 3, 2020

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.

@alasdairgallacher
Copy link
Contributor Author

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 is not going well haha! Thank you, I think I've sorted it now 🤞

@alaouy
Copy link
Owner

alaouy commented May 13, 2020

@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

@alasdairgallacher
Copy link
Contributor Author

@alasdairgallacher This looks good to me, please just add this to the readme doc, otherwise nobody will know that it exists ; )

@alaouy Thank you! I've added to the readme doc under usage section. Please let me know if anything needs changing 👍

@alaouy alaouy merged commit be04bbe into alaouy:master May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants