403 Laravel 中禁止

问题描述 投票:0回答:1

说明: 每当我访问 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');
        }

    }

});
php laravel routes http-status-code-403 laravel-11
1个回答
0
投票
Route::prefix('storage')->match(['GET', 'POST'], '{any?}', function (Request $request) {

})->where('any', '.*');

这接受任意数量的 URI。

© www.soinside.com 2019 - 2024. All rights reserved.