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/configurationThe details in error msg shows me the method is Get.
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


$requestinsidedbmethod, what$database->setup($request->db); $app->setup($request);does, etc.?https://link, and you're forcinghttpin production withapp('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