1

I am trying to make a post request to the example url endpoint but I keeping running into this weird error "The GET method is not supported for this route. Supported methods: POST." Bellow is my code route and controller code:

Route Snippet: Route::post('/posts', 'PostController@store')->name('store');

Controller Snippet:

public function store(){
        $client = new \GuzzleHttp\Client();
        $url = "https://cdc-npin.lndo.site/api/nhtd-event/json";
        $response = $client->post($url, [
            'form_params' => [
                'key1' =>  'value1',
                'key2' =>  'value2',
                'key3' =>  'value3',
                'key4' =>  'value4',
            ]
        ]);
         dd($response

What am I not doing correctly??

2
  • Typo fix, it's dd($response); and not dd($response Commented Dec 3, 2019 at 16:19
  • Can you post the form that submits to this store method? I suspect the error is coming before you even get to the Guzzle client Commented Dec 3, 2019 at 17:01

2 Answers 2

1

This is not form value;

'form_params' => [
                'key1' =>  'value1',
                'key2' =>  'value2',
                'key3' =>  'value3',
                'key4' =>  'value4',
            ]

with form values, controller looks like

     public function store(Request $request){
        $client = new \GuzzleHttp\Client();
        $url = "https://cdc-npin.lndo.site/api/nhtd-event/json";
        $response = $client->post($url, [
            'form_params' => [
                'first_name' => $request->get('first_name'),
                'last_name' => $request->get('last_name'),
                'email' => $request->get('email'),
                'job_title' => $request->get('job_title'),
                'city' => $request->get('city'),
                'country' => $request->get('country')
            ]
        ]);
         dd($response);
    }

and the form looks like:

<form method="post" action="{{ route('store') }}">
          @csrf
          <div class="form-group">    
              <label for="first_name">First Name:</label>
              <input type="text" class="form-control" name="first_name"/>
          </div>

          <div class="form-group">
              <label for="last_name">Last Name:</label>
              <input type="text" class="form-control" name="last_name"/>
          </div>

          <div class="form-group">
              <label for="email">Email:</label>
              <input type="text" class="form-control" name="email"/>
          </div>
          <div class="form-group">
              <label for="city">City:</label>
              <input type="text" class="form-control" name="city"/>
          </div>
          <div class="form-group">
              <label for="country">Country:</label>
              <input type="text" class="form-control" name="country"/>
          </div>
          <div class="form-group">
              <label for="job_title">Job Title:</label>
              <input type="text" class="form-control" name="job_title"/>
          </div>                         
          <button type="submit" class="btn btn-primary-outline">Add contact</button>
      </form>
Sign up to request clarification or add additional context in comments.

2 Comments

I'm not sure that this is the problem since it should be causing an error in template rendering but you have a typo in your form definition in the action attribute. route(store') should be route('store')
Not the cause of the problem definitely!
1

"The GET method is not supported for this route. Supported methods: POST." Not is the output of

dd($reponse);

I guess that you have a problem with the Form that calls the route Post::store, your form seems like make a GET Request instead a POST Request, cause the error is from controller not of Guzzle.

I see your form, the form and method is correct...

What if you change the constructor of Guzzle by

$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://cdc-npin.lndo.site/api/nhtd-event/json', [
    'form_params' => [
        'first_name' => $request->get('first_name'),
        'last_name' => $request->get('last_name'),
        'email' => $request->get('email'),
        'job_title' => $request->get('job_title'),
        'city' => $request->get('city'),
        'country' => $request->get('country')
    ]
]);

2 Comments

The error goes away when I remove dd($reponse); but when I visit my enpoint url, I don't see the newly submitted data. Why is my data not registering?
You make the endpoint? you can post here the Route and Controller that handle this URL cdc-npin.lndo.site/api/nhtd-event/json ?

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.