Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

montrealinthefall's avatar

return back(); not working for 1 route, but works perfectly for nearly identical route

I have 2 routes, one for canceling subscription, and one for resuming, and unless I am missing something, both routes are identical except for the names/functions/urls. When I cancel resume the subscription, I click the /resume url, it performs the function, and then returns back, and it's all so fast it seems like it never leaves the page, then it flashes the success message.

My /cancel url just goes to a blank page (I am pretty sure this is correct, because you would never see this if it worked properly) and it performs the cancel function but never returns back. When I manually go back with my back button, it then flashes the success message. Just can't figure out why it will not go back on it's own, as intended. Please tell me if you need any other info besides this.

Working:

Route::get('/resume', function (Request $request) {
// $user = User::find(1);
$user = Auth::user();
$response = $user->subscription()->resume();
toastr()->success('Your subscription has been successfully resumed.', 'Success' , ['closeButton' => 'true','positionClass' => 'toast-top-center']);
return back();
});

Not working:

Route::get('/cancel', function (Request $request) {
// $user = User::find(1);
$user = Auth::user();
$response = $user->subscription()->cancel();
toastr()->success('Your subscription has been successfully cancelled.', 'Success' , ['closeButton' => 'true','positionClass' => 'toast-top-center']);
return back();
});

I feel like these aren't necessary, but just in case, here are the 2 functions in my subscription controller.

public function cancel(): self
    {
        $response = LemonSqueezy::api('DELETE', "subscriptions/{$this->lemon_squeezy_id}");

        $this->sync($response['data']['attributes']);

        return $this;
    }

    /**
     * Resume the subscription.
     */
    public function resume(): self
    {
        if ($this->expired()) {
            throw new LogicException('Cannot resume an expired subscription.');
        }

        $response = LemonSqueezy::api('PATCH', "subscriptions/{$this->lemon_squeezy_id}", [
            'data' => [
                'type' => 'subscriptions',
                'id' => $this->lemon_squeezy_id,
                'attributes' => [
                    'cancelled' => false,
                ],
            ],
        ]);

        $this->sync($response['data']['attributes']);

        return $this;
    }
0 likes
1 reply
montrealinthefall's avatar
Level 1

Solved with a comment on this thread https://laracasts.com/discuss/channels/laravel/redirect-with-not-working?page=1&replyId=337923

I did a manual redirect which was also not working, so I added ->send(); to the end, as that thread suggested, and this fixed it. I did not test this with return back(); but it probably will work for that too.

successful code looks like this

return redirect()->to('/settings/subscription')->send();

Please or to participate in this conversation.