laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.36k stars 10.97k forks source link

MethodNotAllowedHttpException after Authentication #11970

Closed minhchu closed 8 years ago

minhchu commented 8 years ago

I defined my routes like this:

Route::group(['middleware' => 'web'], function () {
    Route::get('/', function () {
        return view('welcome');
    });

    Route::auth();

    Route::get('/home', 'HomeController@index');

    Route::get('/event/{id}', 'EventController@show');

    Route::post('/booking', 'BookingController@store');
});

And I added auth middleware in my BookingController's constructor:

public function __construct()
{
    $this->middleware('auth', ['only' => 'store']);
}
  1. Users visit event page. This is the form.
  2. Users POST their information.
  3. Not authenticated so redirect to the login form.
  4. Users log in
  5. Redirect to /booking . Now it is GET request.

I assume that auth middleware have to maintain the request after it is passed through. So it must redirect to /booking with POST method. Please let me know if this is a bug or the way laravel working. I'm using Laravel 5.2.10

GrahamCampbell commented 8 years ago

Thanks but this is actually a known bug and is a duplicate.

GrahamCampbell commented 8 years ago

https://github.com/laravel/framework/pull/11120

minhchu commented 8 years ago

Thanks. Can I make a PR because Taylor said that he had never had this issue https://github.com/laravel/framework/pull/11120#issuecomment-161405604

snapey commented 8 years ago

I don't think this is a bug because http does not natively support redirects as POST requests. See; http://programmers.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect

minhchu commented 8 years ago

@GrahamCampbell could you check again

syaiful6 commented 8 years ago

why you let user see the form then? protect your route event with auth

minhchu commented 8 years ago

@syaiful6 it's just for UX. It's kind the same as check out a cart. You dont have to login until the payment step.

testingtoolsco commented 7 years ago

This is exactly, what anyone would want to have the greater the user experience the greater the usage of an application, otherwise its just like any other website or application in a black hole, in the current world of modernization if User eXperience ( UX ) is not given importance while building the enterprise of end user applications there is no use to even thinking of developing it.

I understand that http does not allow this, but instead, if laravel can come up with this, like for example, when some thing is redirected to login, first store the request object and see what is the current request type be it be POST / PATCH / DELETE and then once the login is successful, while doing a redirect, instead of redirecting why cant it do a request like a POST request or what ever based on the earlier action and details stored.. that will give a great User eXperience ( UX ) as mentioned by @minhchu

And it will be a great attraction for Laravel as well, many developers would love this feature to be part of Laravel Framework as it will save a lot of time in developing these features.