lundi 27 novembre 2017

Laravel GET route error MethodNotAllowedHttpException

I have a very simple web app created in Laravel 5.5:

There is a database with a list of coupon codes that have either not been redeemed or been redeemed. 0 is not redeemed and 1 is redeemed.

When someone enters a string into a HTML form input and submits it, Laravel goes to a route with that string as a variable.

The Controller code is as follows:

public function redeemCoupon ($coupon_code)

    {
        $coupon = Coupon::where('coupon_code', $coupon_code)->first();

        if ($coupon === null) {
            return view ('pages.no-coupon');
        }

        else if ($coupon->redeemed == 1) {
            return view ('pages.used-coupon');  
        }
        else {

            $coupon->redeemed = 1;
            $coupon->update();
            return view('pages.redeemed-coupon', compact('coupon') );
        }
    }

Route:

Route::post('/redeem-coupon/{coupon_code}', 'CouponController@redeemCoupon');

You can try it out here: http://178.62.4.225

Everything works fine when done normally, tested on the code "code01". When I enter it and it hasn't been redeemed, it says so, and redeeming it changes the column in the database from 0 to 1. If I try the process again it tells me it has already been redeemed.

The issue is when I'm on the page that tells me it's been redeemed: http://ift.tt/2A8CpH0

If I refresh it with CTRL + R, it just reloads and says it's already been redeemed. But if I paste the URL into a new tab or click into it and refresh by clicking enter, it gives " MethodNotAllowedHttpException" and the resulting debug screen, from what I can tell, offers nothing of use.

Help!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire