The following routing rules limit the id to numbers. If it is not a number, an error will be reported. How to set it to prompt an incorrect parameter, a non-existent article, or jump to the homepage when it is not a number?
Route::get('article/{id}', function($id) {
return 'Article:' . $id;
})->where('id', '[0-9]+');
我想大声告诉你2017-05-16 16:58:21
Method 1
Route::get('article/{id}', function($id) {
if(is_numeric($id)) {
return 'Article:' . $id;
} else {
return 'Index'
}
});
Method 2
Route::group(['prefix' => 'article/'], function() {
Route::get('{id}', function($id) {
return 'Article:' . $id;
})->where('id', '[0-9]+');
Route::get('{id}', function($id) {
return 'Index:'.$id;
});
});
PHP中文网2017-05-16 16:58:21
Create fileresourcesviewserrors404.blade.php
Non-existing routes will jump to this file, the specific processing is written in this file