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.
missing()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!