0

I am trying to store model data using CustomRequest with validation rules.

CustomController.php

/**
     * Store a newly created Exams in storage.
     *
     * @param CustomRequest $request
     *
     * @return Response
     */
    public function store(CustomRequest $request)
    {
        return new storeResponse($request);
    }

CustomRequest.php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CustomRequest extends FormRequest
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return ['title' => 'required'];
    }
}

It works fine with normal Request class.


The error I am getting

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException The GET method is not supported for this route. Supported methods: POST.

6
  • 1
    Check your browser's network inspector and verify you're actually making a POST request and not a GET request. Commented Aug 22, 2020 at 9:09
  • I am not using api. It's normal php post form submit. And it's working fine when I replace CustomRequest with Illuminate\Http\Request Commented Aug 22, 2020 at 9:13
  • 1
    Maybe this helps: stackoverflow.com/a/48136262/2568469 Commented Aug 22, 2020 at 9:54
  • 1
    What does you using an api or not have to do with this? A browser's web inspector captures all traffic. Commented Aug 22, 2020 at 11:49
  • 1
    @hatef adding failedValidation method worked, the 2nd answer. Thanks stackoverflow.com/a/48136194/4414952 Commented Aug 22, 2020 at 13:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.