php - 403 Forbidden in Laravel - Stack Overflow

Description:Whenever I visit the URI 'storagedecodehello' the 403 error is shown, but whe

Description: Whenever I visit the URI '/storage/decode/hello' the 403 error is shown, but when I go to '/storage/decode' URI, then the code works perfectly fine.

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');
        }

    }

});

Description: Whenever I visit the URI '/storage/decode/hello' the 403 error is shown, but when I go to '/storage/decode' URI, then the code works perfectly fine.

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');
        }

    }

});
Share Improve this question asked Nov 17, 2024 at 14:13 Diwash MainaliDiwash Mainali 634 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
Route::prefix('storage')->match(['GET', 'POST'], '{any?}', function (Request $request) {

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

This accepts any number of URIs.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745631048a4637110.html

相关推荐

  • php - 403 Forbidden in Laravel - Stack Overflow

    Description:Whenever I visit the URI 'storagedecodehello' the 403 error is shown, but whe

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信