Skip to content

Commit c74a3fa

Browse files
author
shukri yusof
committed
feat: add video id rule validation
1 parent 8e047c8 commit c74a3fa

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
namespace Vimeo\Laravel\Rules;
3+
4+
use Illuminate\Contracts\Validation\Rule;
5+
use Vimeo\Laravel\Facades\Vimeo;
6+
7+
class VimeoVideoIdValidationRule implements Rule
8+
{
9+
/**
10+
* Determine if the validation rule passes.
11+
*
12+
* @param string $attribute
13+
* @param mixed $value
14+
* @return bool
15+
*/
16+
public function passes($attribute, $value)
17+
{
18+
// Make an API request to Vimeo to check if the video with the given ID exists.
19+
// Replace 'your-api-endpoint' with the actual API endpoint you want to use.
20+
$response = Vimeo::request('/videos/'.$value, [], 'GET');
21+
22+
// Check if the response status is 200, indicating a successful request.
23+
return data_get($response, 'status') === 200;
24+
}
25+
26+
/**
27+
* Get the validation error message.
28+
*
29+
* @return string
30+
*/
31+
public function message()
32+
{
33+
// Return a generic error message if the validation fails.
34+
return __('The :attribute format is invalid.');
35+
}
36+
}

0 commit comments

Comments
 (0)