Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567



New Laravel Route “Missing” Method

With the release of Laravel v8.26.0, the Router has a new missing() method for a convenient way to handle missing records when using route model binding.

By default, route model binding will return a 404 if someone tries to access an non-existent record. Currently, you’d need some customization to check and handle it accordingly. With the addition of the missing() method this scenario is much simpler:

Route::get('/locations/{location:slug}', [LocationsController::class, 'show'])
     ->missing(function (Request $request) {
         return Redirect::route('locations.index');

The missing() method works with route caching and should clean up scenarios where you’d like some custom handling when route model binding throws a ModelNotFound exception.

It’s features like this that make Laravel such a pleasure to use. A HUGE shout out to Adam Campbell for contributing this feature!

Learn More

This method is documented with routing under Customizing Missing Model Behavior. If you’d like to learn more about the implementation of this feature, check out Pull Request #36035.

Filed in:

Credit: Source link

Previous Next
Test Caption
Test Description goes like this