Last active
August 29, 2015 14:19
-
-
Save GRAgmLauncher/7a4957d923fecfcc107f to your computer and use it in GitHub Desktop.
API request validator concept
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
<?php | |
class APIRequest extends FormRequest | |
{ | |
public function response(array $errors) | |
{ | |
if ($this->ajax() || $this->wantsJson()) | |
{ | |
return new JsonResponse($errors, $this->responseCode()); | |
} | |
} | |
protected function responseCode() | |
{ | |
return 422; | |
} | |
} |
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
<?php | |
class SomeEndpointRequest extends APIRequest | |
{ | |
protected function responseCode() | |
{ | |
return 417; | |
} | |
public function rules() | |
{ | |
... | |
} | |
public function messages() | |
{ | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment