I'm building my first laravel API and when I try to validate some mock form data using Postman with POST method, the application returns to me the HTML of the index page and status 200.
Here is my code
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'slug' => 'required',
'price' => 'required'
]);
return Product::create($request->all());
}
The application returns the object that was inserted in the database if the validation was successful (if the data was filled in), but returns a HTML file otherwise.
How can I change the way the method 'validate()' operates? I'm guessing it is just returning the user to the main page if the form data was not filled correctly
I am using Laravel 8
source https://stackoverflow.com/questions/68595460/laravel-validate-method-returns-index-html-page-when-false
Comments
Post a Comment