You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem:
When a user navigates directly to a URL (no HTTP_REFERER) and this user has no abilities to view this page (see the example code below), redirect()->back() redirects to the same page, causing an infinite loop.
Example of redirect back in the controller:
if (auth()->user()->cannot('viewAny', Example::class)) {
return redirect()->back()->with('status', 'You are not authorized!')
}
The $fallback parameter only triggers when HTTP_REFERER is completely absent, but not when it equals the current URL.
Proposed solution:
Modify Redirector::back() to also compare previous URL with current URL, and use a configurable fallback URL:
Add fallback_url to config/app.php and FALLBACK_URL parameter to .env file:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Problem:
When a user navigates directly to a URL (no HTTP_REFERER) and this user has no abilities to view this page (see the example code below), redirect()->back() redirects to the same page, causing an infinite loop.
Example of redirect back in the controller:
The $fallback parameter only triggers when HTTP_REFERER is completely absent, but not when it equals the current URL.
Proposed solution:
Modify Redirector::back() to also compare previous URL with current URL, and use a configurable fallback URL:
'fallback_url' => env('FALLBACK_URL', '/'),
Beta Was this translation helpful? Give feedback.
All reactions