This is probably something super basic but consider the route file:
Route::get('/', 'WelcomeController@getIndex');
Route::post('/', 'WelcomeController@postIndex');
Route::get('/registered-games', 'GameController@getIndex');
When I am on getIndex
for WelcomeController
and I make a post via a form I should be redirected back to the getIndex
as per the controller below:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Squidward\Domain\Entities\GameEntity;
class WelcomeController extends Controller {
public function getIndex() {
return view('welcome', ['homeEnabled' => true]);
}
public function postIndex(Request $request) {
$gameEntity = new GameEntity();
$gameEntity->name = $request['game_name'];
$gameEntity->save();
return redirect('/')->with('success', 'Game has been registered successfully.');
}
}
But Instead I get:
MethodNotAllowedHttpException in RouteCollection.php line 219:
in RouteCollection.php line 219
at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 206
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 754
at Router->findRoute(object(Request)) in Router.php line 663
at Router->dispatchToRoute(object(Request)) in Router.php line 639
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
....
I am sure its something super basic and noobish but this error doesn't make sense to me ...
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire