Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

varundavda's avatar

Form method "POST" but sending only "GET" request.

Hello,

I am going through flyer series. Step by step. I have my route setup like this.

<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

Route::get('/', function () {
    return view('pages.home');
});

Route::resource('flyers','FlyersController');

Route::get('{zip}/{street}','FlyersController@show');
Route::post('{zip}/{street}/photos',['as' => 'store_photo_path', 'uses' => 'FlyersController@addPhoto']);

I have created a form like this


@extends('layout')

@section('content')

    <h1>Selling your home?</h1>

    <form action="/flyers" method="POST">
        
        @include('flyers.form')
        
        @include('errors')

    </form>


@stop

My form.blade.php includes the following code.

@inject('countries','App\Http\Utilities\Country')

<div class="row">

    <div class="col-md-6">

        {{ csrf_field() }}

        <div class="form-group">
            <label for="street">Street:</label>
            <input type="text" name="street" id="street" class="form-control" value="{{old('street')}}" />
        </div>

        <div class="form-group">
            <label for="city">City:</label>
            <input type="text" name="city" id="city" class="form-control" value="{{old('city')}}" />
        </div>

        <div class="form-group">
            <label for="zip">Zip / Postal Code:</label>
            <input type="text" name="zip" id="zip" class="form-control" value="{{old('zip')}}" />
        </div>


        <div class="form-group">
            <label for="country">Country:</label>
            <select id="country" name="country" class="form-control">
                @foreach($countries::all() as $country => $code)
                    <option value="{{$code}}">{{$country}}</option>
                @endforeach
            </select>
        </div>

        <div class="form-group">
            <label for="country">State:</label>
            <input type="text" name="state" id="state" class="form-control" value="{{old('state')}}" />
        </div>

    </div>    
    
    <div class="col-md-6">

        <div class="form-group">
            <label for="price">Sale Price:</label>
            <input type="text" name="price" id="price" class="form-control" value="{{old('price')}}" />
        </div>

        <div class="form-group">
            <label for="description">Home Description:</label>
            <textarea type="text" name="description" rows="10" id="description" class="form-control">
                {{old('description')}}
            </textarea>
        </div>

    </div>

    <div class="col-md-12">
        <hr>
        
        <div class="form-group">
            <button class="btn btn-primary" type="submit">Create Flyer</button>
        </div>

    </div>

</div>@inject('countries','App\Http\Utilities\Country')

<div class="row">

    <div class="col-md-6">

        {{ csrf_field() }}

        <div class="form-group">
            <label for="street">Street:</label>
            <input type="text" name="street" id="street" class="form-control" value="{{old('street')}}" />
        </div>

        <div class="form-group">
            <label for="city">City:</label>
            <input type="text" name="city" id="city" class="form-control" value="{{old('city')}}" />
        </div>

        <div class="form-group">
            <label for="zip">Zip / Postal Code:</label>
            <input type="text" name="zip" id="zip" class="form-control" value="{{old('zip')}}" />
        </div>


        <div class="form-group">
            <label for="country">Country:</label>
            <select id="country" name="country" class="form-control">
                @foreach($countries::all() as $country => $code)
                    <option value="{{$code}}">{{$country}}</option>
                @endforeach
            </select>
        </div>

        <div class="form-group">
            <label for="country">State:</label>
            <input type="text" name="state" id="state" class="form-control" value="{{old('state')}}" />
        </div>

    </div>    
    
    <div class="col-md-6">

        <div class="form-group">
            <label for="price">Sale Price:</label>
            <input type="text" name="price" id="price" class="form-control" value="{{old('price')}}" />
        </div>

        <div class="form-group">
            <label for="description">Home Description:</label>
            <textarea type="text" name="description" rows="10" id="description" class="form-control">
                {{old('description')}}
            </textarea>
        </div>

    </div>

    <div class="col-md-12">
        <hr>
        
        <div class="form-group">
            <button class="btn btn-primary" type="submit">Create Flyer</button>
        </div>

    </div>

</div>

Now the problem i am facing is that when click on submit button, the form does not get submitted. It send a GET request to /flyers. It should send a POST request but it sends a GET request. I tried with some other URL like "/testUrl" and it worked fine and sent an POST request.

I cannot figure out why this send an GET request and not a POST request.

I also tried php artisan route:list.

It gave the following output.

C:\xampp\htdocs\flyer>php artisan route:list
+--------+----------+-----------------------+------------------+-------------------------------------------------------+------------+
| Domain | Method   | URI                   | Name             | Action                                                | Middleware |
+--------+----------+-----------------------+------------------+-------------------------------------------------------+------------+
|        | GET|HEAD | /                     |                  | Closure                                               |            |
|        | GET|HEAD | auth/login            |                  | App\Http\Controllers\Auth\AuthController@getLogin     | guest      |
|        | POST     | auth/login            |                  | App\Http\Controllers\Auth\AuthController@postLogin    | guest      |
|        | GET|HEAD | auth/logout           |                  | App\Http\Controllers\Auth\AuthController@getLogout    |            |
|        | GET|HEAD | auth/register         |                  | App\Http\Controllers\Auth\AuthController@getRegister  | guest      |
|        | POST     | auth/register         |                  | App\Http\Controllers\Auth\AuthController@postRegister | guest      |
|        | POST     | flyers                | flyers.store     | App\Http\Controllers\FlyersController@store           | auth       |
|        | GET|HEAD | flyers                | flyers.index     | App\Http\Controllers\FlyersController@index           | auth       |
|        | GET|HEAD | flyers/create         | flyers.create    | App\Http\Controllers\FlyersController@create          | auth       |
|        | PATCH    | flyers/{flyers}       |                  | App\Http\Controllers\FlyersController@update          | auth       |
|        | DELETE   | flyers/{flyers}       | flyers.destroy   | App\Http\Controllers\FlyersController@destroy         | auth       |
|        | PUT      | flyers/{flyers}       | flyers.update    | App\Http\Controllers\FlyersController@update          | auth       |
|        | GET|HEAD | flyers/{flyers}       | flyers.show      | App\Http\Controllers\FlyersController@show            |            |
|        | GET|HEAD | flyers/{flyers}/edit  | flyers.edit      | App\Http\Controllers\FlyersController@edit            | auth       |
|        | GET|HEAD | test                  |                  | App\Http\Controllers\FlyersController@ftp             | auth       |
|        | GET|HEAD | {zip}/{street}        |                  | App\Http\Controllers\FlyersController@show            |            |
|        | POST     | {zip}/{street}/photos | store_photo_path | App\Http\Controllers\FlyersController@addPhoto        | auth       |
+--------+----------+-----------------------+------------------+-------------------------------------------------------+------------+
0 likes
6 replies
Jaytee's avatar

In the form action, link it to the named route. In this case for the POST named route, you'd do:

<form action="{{ route('flyers.store') }}">

It's likely that it isn't picking up the POST request because I'm certain, any routes you declare on the same Controller that's being used as a Resource, must come before the Resource route.

// This is what you have

Route::resource('flyers','FlyersController');

Route::get('{zip}/{street}','FlyersController@show');
Route::post('{zip}/{street}/photos',['as' => 'store_photo_path', 'uses' => 'FlyersController@addPhoto']);
// Try moving the two separate routes above the resource
Route::get('{zip}/{street}','FlyersController@show');
Route::post('{zip}/{street}/photos',['as' => 'store_photo_path', 'uses' => 'FlyersController@addPhoto']);
Route::resource('flyers','FlyersController');
``
varundavda's avatar

@DPJack thanks.

But still same result. It sends a GET request to flyers.local/flyers

Jaytee's avatar

@varundavda Can you prove that you're receiving a GET request please. Also show the FlyersController.

varundavda's avatar

@DPJack Here is the controller code.

Thank you.

<?php

namespace App\Http\Controllers;

use Storage;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Requests\FlyerRequest;
use App\Http\Controllers\Controller;
use App\Flyer;
use App\Photo;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class FlyersController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth', ['except' => ['show']]);
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $this->show();
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {   
        return view('flyers.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(FlyerRequest $request)
    {   
        dd('here');
          
        Flyer::create($request->input());

        flash()->overlay('Welcome Aboard','Thanks for signing up.');

        return redirect()->back();
    
    }
    

    public function show($zip,$street)
    {   
        $flyer = Flyer::locatedAt($zip,$street);

        return view('flyers.show',compact('flyer'));
    }

    public function addPhoto($zip, $street, Request $request)
    {

        $this->validate($request,[

            'photo' => 'required|mimes:jpg,jpeg,png,bmp'

        ]);

        $photo = $this->makePhoto($request->file('photo'));

        $flyer = Flyer::locatedAt($zip,$street)->addPhoto($photo)->store();

        
    }

    protected function makePhoto(UploadedFile $file)
    {

        return Photo::named($file->getClientOriginalName())->move($file);

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

    public function ftp($request)
    {

        $name = time() . $request->file('photo')->getClientOriginalName();

        Storage::disk('ftp')->put($name, $request->file('photo'));

        // $disk = Storage::disk('ftp');

        // // $file = $request->file('photo');

        // // $file->move($this->baseDir, $name);

        // Storage::put($photo, $disk);
    }
}

EventFellows's avatar

I believe you are mixing 2 approaches here (not 100% sure):

'Action' requires a controller and method to be specified like:

action="FlyerController@store"

Alternatively you should be able to use a named route

route="flyers.store"

Using 'action' and then providing a route name might screw up things (not sure why is does a GET request, though)

varundavda's avatar

I used Laravel form builder, and everything worked fine.

Please or to participate in this conversation.