说明: 每当我访问 URI '/storage/decode/hello' 时,都会显示 403 错误,但是当我访问 '/storage/decode' URI 时,代码就可以正常工作。
Route::prefix('storage')->match(['GET', 'POST'], '{any?}', function (Request $request) {
$requestedUri = $request->getRequestUri();
$requestedUri_array = explode('/', $requestedUri);
$task = $requestedUri_array[2];
if ($request->isMethod('get')) {
if ($task == 'decode') {
if ( ! isset($requestedUri_array[3])) {
return "Bro you are in wrong place.";
}
return "Yes bro right place to be";
}
}
if ($request->isMethod('post')) {
if ($task == 'encode') {
if ( ! isset($requestedUri_array[3])) {
dd(['success' => 'false', 'message' => 'Please provide valid data to store']);
}
$encryptedVal = encrypt($requestedUri_array[3]);
dd($encryptedVal);
} else {
dd('Invalid URL');
}
}
});
Route::prefix('storage')->match(['GET', 'POST'], '{any?}', function (Request $request) {
})->where('any', '.*');
这接受任意数量的 URI。