Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Ability to build a response using a fallback route name #21299

Merged
merged 3 commits into from
Sep 21, 2017
Merged

[5.5] Ability to build a response using a fallback route name #21299

merged 3 commits into from
Sep 21, 2017

Conversation

themsaid
Copy link
Member

@themsaid themsaid commented Sep 20, 2017

Having:

Route::fallback('ServersController@notFound')->name('notFoundServer');

In your exception handler or inside another route you can do:

return Route::respondWith('notFoundServer');

This will run the ServersController@notFound action and return its response.

This is useful for when you want to catch a ModelNotFound exception and return a fallback route instead of the 404.blade.php view.

@themsaid themsaid changed the title [5.5] Ability to build a response using a route name [5.5] Ability to build a response using a fallback route name Sep 20, 2017
@sisve
Copy link
Contributor

sisve commented Sep 20, 2017

Would this support route middlewares like StartSession so we can get session support on the custom 404 pages?

@themsaid
Copy link
Member Author

@sisve yes

@taylorotwell taylorotwell merged commit 35b858b into laravel:5.5 Sep 21, 2017
@decadence
Copy link
Contributor

decadence commented Sep 21, 2017

@themsaid Is this can be used with any route name?

@browner12
Copy link
Contributor

@decadence I was able to use it with any route name.

@decadence
Copy link
Contributor

@browner12
Any route as long as it doesn't require parameters © @themsaid

@unstoppablecarl
Copy link
Contributor

unstoppablecarl commented Sep 22, 2017

Where would be the best place to catch response exceptions and return Route::respondWith('notFoundServer'); to override of normal behavior in the whole app?

@themsaid
Copy link
Member Author

@unstoppablecarl the exception handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants