I have a form on my first page like this
{{ Form::open() }}
{{ Form::text('invite_code', null, array('placeholder' => 'Skriv in din injudningskod h盲r...')) }}
{{ Form::submit('G氓 vidare') }}
{{ Form::close() }}
The routes looks like this.
Route::get('/', 'InviteController@getInvite');
Route::post('/', 'InviteController@postInvite');
When posting I only get 301 and is redirected to the Route::get route.
If I change the form and routes to use /invite when using posts instead all works fine...
Route::get('/', 'InviteController@getInvite');
Route::post('/invite', 'InviteController@postInvite');
Is there a reason I can't send post requests to first page?
Try just passing a blank string to the route instead of a backslash. You may also have to have your form post to the homepage without a trailing slash.
nope, did not solve it. Still getting 301
Are you sure it's not a cached 301? https://github.com/laravel/framework/issues/1438?source=cc#issuecomment-18618087
Tried in incognito and also clearing cache with artisan. Nothing helped. But after reading the thread you linked the problem seems to be with chrome. It automatically adds a trailing slash every time I visit localhost/project/public. No matter how, it always adds it :-p . Solved it by defining which action to be used by the form
{{ Form::open(array('action' => 'InviteController@postInvite')) }}
Thanks! Was looking so long for this. I didn't know that a trailing slash would result in a redirect. Especially since my local vagrant environment worked fine but production was causing issues. Finally solved all my issues :)
nope, did not solve it. Still getting 301
My problem got solved when I sent post request without forward slash
Clearing browser cache did it for me.
The issue was caused by messed middleware in app/Http/Middleware, that Chrome had cached
nope, did not solve it. Still getting 301
My problem got solved when I sent post request without forward slash
same here!,,, why?
Thank god! Was tearing my hair out. The end forward slash work locally but not on prod, only difference I can think of is on prod I have SSL enabled.
Most helpful comment
My problem got solved when I sent post request without forward slash