We're creating a REST API for our application.
web.php
Route::post('add-new-student', 'StudentController@addNewStudent');
StudentController.php
...
function addNewStudent(Request $request)
{
$validation = $request->validate([
'student_mobile' => 'required|digits:10',
'student_name' => 'required|min:3|max:50',
'student_email' => 'email:rfc|max:50',
]);
if ($validation->fails()) {
// show error json
} else {
// add new student
}
}
...
Now when we send the JSON response, if there is error, instead of going to else block it shows 404 page in postman.
We don't know what we are doing wrong!
Note
- Our routes are correct (double checked)
- In postman, we are sending post request