-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add another example for facade
- Loading branch information
1 parent
c0ba374
commit 659ac6c
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace Vimeo\Laravel\Rules; | ||
|
||
use Illuminate\Contracts\Validation\Rule; | ||
use Vimeo\Laravel\Facades\Vimeo; | ||
|
||
class VimeoVideoIdValidationRule implements Rule | ||
{ | ||
/** | ||
* Determine if the validation rule passes. | ||
* | ||
* @param string $attribute | ||
* @param mixed $value | ||
* @return bool | ||
*/ | ||
public function passes($attribute, $value) | ||
{ | ||
// Make an API request to Vimeo to check if the video with the given ID exists. | ||
// Replace 'your-api-endpoint' with the actual API endpoint you want to use. | ||
$response = Vimeo::request('/videos/'.$value, [], 'GET'); | ||
|
||
// Check if the response status is 200, indicating a successful request. | ||
return data_get($response, 'status') === 200; | ||
} | ||
|
||
/** | ||
* Get the validation error message. | ||
* | ||
* @return string | ||
*/ | ||
public function message() | ||
{ | ||
// Return a generic error message if the validation fails. | ||
return __('The :attribute format is invalid.'); | ||
} | ||
} |