1

PHP version: 7.4.33
Laravel version: 5.8

when I hit the post route, it shows in the error page that I sent it as Get, and this route supports Post.

  • this is the error msg: Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

    The GET method is not supported for this route. Supported methods: POST.

  • The route I hit is install/db/configuration

  • The details in error msg shows me the method is Get.

    enter image description here

  • However, the Method is Post either in the Route or View File.

  • I dd($request) for the method in db method controller and it shows prints Post

  • I tried all the cache clear commands and the optimize.

  • I even made sure the route in the AppServiceProvider hits http not https.

  • Here is the Route File:

<?php


Route::post('install/db/configuration'  ,'InstallController@db')->name('store.db.configurations');

Route::get('install/app'                , 'InstallController@installation')->name('installation');
Route::get('install/configuration'      , 'InstallController@configurations')->name('show.configurations');
Route::post('install/configuration'     , 'InstallController@store')->name('store.configurations');
Route::post('install/app/configuration' , 'InstallController@app')->name('store.app.configurations');
Route::get('install/complete'           , 'InstallController@complete')->name('complete.installation');
  • Here is the Controller:
class InstallController extends Controller
{
    public function __construct()
    {
        $this->middleware(RedirectIfInstalled::class);
    }

    public function installation(Requirement $requirement)
    {
        return view('install.new', compact('requirement'));
    }

    public function configurations(Requirement $requirement)
    {
        if (! $requirement->satisfied()) {
            return redirect()->name('installation');
        }

        return view('install.db_configuration', compact('requirement'));
    }

    public function db(InstallDatabaseRequest $request,Database $database,App $app)
    {
        $database->setup($request->db);
        $app->setup($request);

        return view('install.app_configuration');
    }

    public function app(InstallAppRequest $request,FinalInstallation $final,AdminAccount $admin)
    {
        $final->setup($request);
        $admin->setup($request);

        return redirect()->route('complete.installation');
    }

    public function complete()
    {
        if (env('APP_INSTALLED') == true) {
            return redirect()->route('dashboard.home');
        }

        DotenvEditor::setKey('APP_INSTALLED', 'true')->save();

        return view('install.complete');
    }
}

Here the setup method in both database and app classes:

class Database
{
    public function setup($data)
    {
        $this->checkDatabaseConnection($data);
        $this->setEnvVariables($data);
    }

    private function checkDatabaseConnection($data)
    {
        $this->setupDatabaseConnectionConfig($data);

        DB::connection('mysql')->reconnect();
        DB::connection('mysql')->getPdo();
    }
    // code goes here
}

class App
{
    public function setup($request)
    {
        $this->generateAppKey();
        $this->setEnvVariables($request);
        $this->setAppSettings($request);
    }

    private function generateAppKey()
    {
        Artisan::call('key:generate', ['--force' => true]);
    }

    private function setEnvVariables($request)
    {
        $env = DotenvEditor::load();

        $env->setKey('APP_ENV'    , 'local');
        $env->setKey('APP_DEBUG'  , 'true');
        $env->setKey('APP_URL'    , url('/') );

        $env->save();
    }
   // code goes here
}

  • Here is the Some of the View:
<form method="POST" action="{{ url(route('store.db.configurations')) }}" class="form-horizontal">
        {{ csrf_field() }}
        <div class="box">
         // lots of code goes here for the styling
        <div class="content-buttons clearfix">
            <button type="submit" class="btn btn-primary pull-right install-button">Submit</button>
        </div>
</form>
  • AppServiceProcider Code:
public function boot()
    {
        if (app()->environment('production')) {
           app('url')->forceScheme('http');
        }
    }
  • Here is route:list for the install/db/configuration route:
|        | GET|HEAD                               | install/app                             | installation
  | App\Http\Controllers\InstallController@installation                       | web,App\Http\Middleware\RedirectIfInstalled   
                                                                         |
|        | POST                                   | install/app/configuration               | store.app.configurations        
  | App\Http\Controllers\InstallController@app                                | web,App\Http\Middleware\RedirectIfInstalled   
                                                                         |
|        | GET|HEAD                               | install/complete                        | complete.installation
  | App\Http\Controllers\InstallController@complete                           | web,App\Http\Middleware\RedirectIfInstalled   
                                                                         |
|        | GET|HEAD                               | install/configuration                   | show.configurations
  | App\Http\Controllers\InstallController@configurations                     | web,App\Http\Middleware\RedirectIfInstalled   
                                                                         |
|        | POST                                   | install/configuration                   | store.configurations
  | App\Http\Controllers\InstallController@store                              | web,App\Http\Middleware\RedirectIfInstalled   
                                                                         |
|        | POST                                   | install/db/configuration                | store.db.configurations
  | App\Http\Controllers\InstallController@db                                 | web,App\Http\Middleware\RedirectIfInstalled   
  • Network tab enter image description here

enter image description here

12
  • 2
    Bring up your browser's developer tools and watch the Network tab as you make the request. You're most likely being redirected (usually happens with HTTP -> HTTPS), which turns a POST into a GET Commented Aug 14, 2024 at 18:12
  • 1
    I think you've made it very clear about the route/method being defined as POST. But, can you explain more about the steps you took to hit the route, what's the value of $request inside db method, what $database->setup($request->db); $app->setup($request); does, etc.? Commented Aug 14, 2024 at 18:23
  • 2
    Check your APP_URL in your .env. If you have that set to a https:// link, and you're forcing http in production with app('url')->forceScheme('http'); (which, really, you should be enforcing https in production), then you're going to get the redirect I was talking about, which breaks your POST route Commented Aug 14, 2024 at 18:56
  • @aynber the request is http, here is the data from network tab: Request URL: 127.0.0.1:8000/install/db/configuration , Request Method: GET Commented Aug 15, 2024 at 11:01
  • @aynber APP_URL=127.0.0.1:8000 , so it is indeed http Commented Aug 15, 2024 at 11:07

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.