Using Laravel CustomRequest on API Resource #53653
Unanswered
ZakaCoding
asked this question in
Q&A
Replies: 2 comments 1 reply
-
You can use this Example code: |string> */ public function rules(): array { return [ 'name' => 'required', ]; } public function failedValidation(Validator $validator) : JsonResponse { $errors = $validator->errors(); throw new HttpResponseException(validationError('Validation Error', errors: $errors)); } } |
Beta Was this translation helpful? Give feedback.
0 replies
-
i have use this before. and still doesn't work |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
11.*
PHP Version
8.*
Database Driver & Version
PostgreSQL
Description
Hello.
i got a problem when using Validator for incoming request. When i use CustomRequest and i test with error, laravel always redirect with Welcome Page, not json response what i want. this is weird.
Is Laravel CustomRequest is only good with WEB Resource ?
Check this code for example.
`
public function show(SomeModel $type, Request $request)
{
$validator = Validator::make($request->all(), [
'uuid' => ['required'],
]);
Steps To Reproduce
i dont know about this :)
Beta Was this translation helpful? Give feedback.
All reactions