I'm trying to validate the request in my API but when I use the validate method or even create a class that extends FormRequest, it gives me the 405 error. Below you can see my controller and the way routes are defined. It only gives me 405 error when the validation fails, I assume, maybe, somehow there is a callback function sending GET method request but I have no clue how to fix it.
<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Interfaces\PostRepositoryInterface;
class PostController extends Controller
{
private $postRepository;
public function __construct(PostRepositoryInterface $postRepository)
{
$this->postRepository = $postRepository;
}
public function index()
{
return $this->postRepository->all();
}
public function store()
{
request()->validate([
'title'=>'required|min:2',
]);
return $this->postRepository->createPost();
}
public function show($postId)
{
return $this->postRepository->findById($postId);
}
}
Error message:
Route::group(['middleware' => 'auth:api', 'namespace'=> 'API'], function(){
Route::get('post' , 'PostController@index' );
Route::post('post' , 'PostController@store' );
Route::get('post/{post}' , 'PostController@show' );
Route::get('post/{post}/edit', 'PostController@edit' );
Route::post('post/{post}' , 'PostController@update' );
Route::post('post/{post}' , 'PostController@destroy');
});