Reputation: 895
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
Upvotes: 0
Views: 197
Reputation: 141
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;
}
Upvotes: 1