Home > Article > PHP Framework > Introducing the new missing method in Laravel8 routing module
The following tutorial column will introduce you to the new missing method in the Laravel 8 routing module. I hope it will be helpful to friends in need!
Laravel version 8.26.0 and above has a newmissing() method in the routing module. In actual development, we often use routing Invisible binding automatically finds the corresponding data, reducing the need to write code in the Controller.
Previously, if the model did not find the corresponding data, it would automatically jump to a globally unified 404 page, which was not flexible enough. Themissing() method is here to solve this problem.
Route::get('/users/{user:slug}', [UserController::class, 'show']) ->name('user.view') ->missing(function (Request $request) { return Redirect::route('user.index'); });
Note: This method is only valid for invisible binding of routes. For example, if you use the
findOrFailmethod in a Controller, even if the specified data is not found, It will not start themissing
method, but will jump to a unified 404 page.
The above is the detailed content of Introducing the new missing method in Laravel8 routing module. For more information, please follow other related articles on the PHP Chinese website!