'Validate field from an api post request
So what I want to do is send an axios request with a field and data to a Laravel controller called VerifyController.php
The function I started to write is:
public function checkUsername(Request $request) {
Validator::make($request, [
'name' => ['required', 'string', 'max:255', 'unique:users'],
])->validate();
return true;
}
All I want to do is send an axios request to /api/verifyusername with the field name and its corresponding data and see if it comes back as available or taken
What does the function need to actually look like? Ive NEVER done this before as I am more of a frontend only guy
Solution 1:[1]
public function checkUsername(Request $request) {
$request->validate([
'name' => ['required', 'string', 'max:255', 'unique:users'],
]);
return true;
}
Or
public function checkUsername(Request $request) {
Validator::make($request->all(), [
'name' => ['required', 'string', 'max:255', 'unique:users'],
])->validate();
return true;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | OSahin |
